Overview

You will learn: how to load a basemap and feature layers from a mobile map package (.mmpk) file.

In this lab, you will use the ArcGIS Runtime SDK for iOS to open a mobile map package on a device when offline. The package is created with ArcGIS Pro, ArcGIS Online or ArcGIS Enterprise using the ArcGIS REST API and loaded to your device as part of application deployment.

Before you begin

Make a copy of the finished Create a starter app lab (or download here) and open the .xcodeproj file in Xcode.

Prepare your data

Complete the lab Prepare your data for offline use. You will use the map package file created in that lab for the offline map data required in this lab.

Steps

Add your map package to your project

  1. In the Prepare your data for offline use data lab, you created a Mobile Map Package (.mmpk) file. Copy that file into your new Xcode project. If you did not complete that lab, you can download the lab's solution here.

Load and display the map package

  1. Open ViewController.swift in the Project Navigator. Replace the setupMap method completely with the code to load a mobile map package and configure the map based on the package contents. Create a AGSMobileMapPackage using the file referenced in the prior step.

    private func setupMap() {
        let mobileMapPackage:AGSMobileMapPackage = AGSMobileMapPackage(name: "devlabs-package")
    }
    
  2. Update the setupMap method to load the map package and check that it loads without error. Display the first map in the package in the map view.

        mobileMapPackage.load { (error) in
            if let error = error {
                print("Error loading the mobile map package: \(error)")
                return
            }
            if let map = mobileMapPackage.maps.first {
                self.mapView.map = map
            }
        }
    
  3. Press Command-R to run the app in the iOS Simulator.

Congratulations, you're done!

Your map should display with the view point centered on the Los Angeles area. Compare your solution with our completed solution project.