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 macOS to open a mobile map package on a Mac when offline. The package is created with ArcGIS Pro and loaded to your Mac as part of the application deployment.

Before you begin

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

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 file here.

Load and display the map package

  1. Create an AGSMobileMapPackage object to load the .mmpk file. Display the first map in the package in the map view.

        ...
        /*** ADD ***/
        var mobileMapPackage:AGSMobileMapPackage?
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            /*** UPDATE ***/
            mobileMapPackage = AGSMobileMapPackage(name: "devlabs-package")
    
            mobileMapPackage?.load { (error) in
                if let error = error {
                    print("Error loading the Mobile Map Package: \(error)")
                    return
                }
    
                if let map = self.mobileMapPackage?.maps.first {
                    self.mapView.map = map
                }
            }
        }
        ...
    
  2. Now press Command-R to run the app.

Congratulations, you're done!

Your map should display with the view point centered on the Los Angeles area.

Your project should look something like this.