Overview

You will learn: how to create a simple starter app that displays a basemap. This template project will be used in subsequent labs.

With the ArcGIS Runtime SDK for iOS, it is easy to create a native mapping app that displays a basemap. In this lab, you will use the iOS SDK to build a simple mapping app that we will use as a starting point for the other iOS labs. This lab demonstrates the basic SDK setup for iOS Xcode projects.

These labs assume you're developing with Xcode and have downloaded and installed the ArcGIS Runtime SDK for iOS to the default location. For a more detailed walk-through of these steps (and to see how to use Cocoapods instead), see Install and set up.

Before you begin

Make sure you have installed the latest version of Xcode.

Download and install the ArcGIS Runtime SDK for iOS by following the instructions at Install and set up.

You will need a developer subscription to download the SDK. If you haven't already, sign up for free.

Steps

Create a starter app

  1. Open Xcode and create a new iOS Swift Single View Application named ArcGIS Starter App.

Hook up the ArcGIS Runtime SDK

  1. In the project target's Build Settings, set Framework Search Paths to $(HOME)/Library/SDKs/ArcGIS/iOS/Frameworks/Static.

  2. In the project target's Build Settings, set Other Linker Flags to -ObjC -framework ArcGIS -l c++.

  3. Add the ArcGIS resource bundle to the project (found in $(HOME)/Library/SDKs/ArcGIS/iOS/Frameworks/Static/ArcGIS.framework/Versions/Current/Resources/).

Add a map to your app

Now that you've created an app and included the ArcGIS Runtime SDK for iOS, the next step is to add a AGSMapView to the storyboard.

  1. Open Main.storyboard in the project navigator and add a new View to the parent view. Add constraints so the new view fills the parent view.

  2. With the new view selected, in Xcode's app menu, select View > Utilities > Show Identity Inspector and in the Identity Inspector (top-right), set the Class attribute to AGSMapView.

  3. Import the ArcGIS SDK into ViewController.swift and add an @IBOutlet named mapView to the ViewController class.

    ...
    import UIKit
    /*** ADD ***/
    import ArcGIS
    
    class ViewController: UIViewController {
    
        /*** ADD ***/
        @IBOutlet weak var mapView: AGSMapView!
    
  4. Create a new private method to configure your map and assign it to the map view.

     private func setupMap() {
         mapView.map = AGSMap(basemapType: .navigationVector, latitude: 34.09042, longitude: -118.71511, levelOfDetail: 10)
     }
    
  5. Call your new method once the view loads.

        ...
        override func viewDidLoad() {
            super.viewDidLoad()
    
            /*** ADD ***/
            setupMap()
        }
    
  6. Open the Main.storyboard and right click on the yellow View Controller icon. Drag the mapView outlet connector to the AGSMapView.

  7. Press Command-R to run the app in the iOS Simulator.

Congratulations, you're done!

Your app should run and display the basemap. Compare your solution with our completed solution project. We will refer back to this project as the starting template for many of the iOS labs.

Challenge

Explore basemaps

Visit the iOS SDK documentation to learn more about the different types of basemaps available. Try some different basemap types such as .lightGrayCanvasVector, .topographicVector or .streetsWithReliefVector and pick your favorite basemap.

Change view

Try different settings for the initial view by changing the latitude, longitude, and level of detail.

Run on a device

If you have an Apple Developer account, try opening the app on a device rather than in the simulator. The Runtime SDK makes extensive use of OpenGL and the iOS simulator performs poorly for tasks that make use of the iOS device's graphics hardware.