Skip To Content ArcGIS for Developers Sign In Dashboard

Open an offline map

You can open an offline map from a mobile map package created by any of the following workflows:

If you created the mobile map package with ArcGIS Pro, you may need to consider whether the mobile map package content has expired. If not, proceed to open the offline map.

Expired mobile map packages

Using ArcGIS Pro 2.4 (or later), you can control the lifetime of your maps by setting an expiration date on your mobile map package. This will allow you to do the following:

  • Provide data to third-party contractors that will expire at the end of a contract.
  • Indicate to your users that the data has become obsolete.
When you use the ArcGIS Pro tool to create the mobile map package, you can set an expiration date and time, an expiration message, and access options if the package has expired.

Note:

These mobile map package expiration properties are available if ArcGIS Pro is licensed with the ArcGIS Publisher extension.

As an ArcGIS Runtime developer, there are three possible outcomes when you try to load a mobile map package:

  1. You have full access to the mobile map package. This situation occurs if the mobile map package has not expired or if it has been created without any expiration properties.
  2. You have full access to the mobile map package even though the maps and their data have expired. You will be warned that the mobile map package is out of date.
  3. You cannot access the mobile map package because it has expired. In this case, the mobile map package will fail to load and you will not be able to access its maps and data.

These three outcomes are managed by the mobile map package load process AGSMobileMapPackage.load. No extra workflow or code paths are required to accommodate this expiration.

If you want to provide your users with extra information, you can retrieve the expiration details from the expiration property on the AGSMobileMapPackage. For example, you can display how many days remain before the mobile map package expires. To do this, perform the following steps:

  1. Load the mobile map package.
  2. Read the expiration property on the mobile map package.
  3. Confirm that the mobile map package has not expired.
  4. Get the expiration date.
  5. Calculate the number of days between today and the expiration date. Report the number of days remaining.

self.mobileMapPackage.load { [weak self] (error) in
 
 // Check load has completed
 guard error == nil else {
  print(error.debugDescription)
  return
 }

 // See if the mobile map package is configured to expire
 if let expiration = self?.mobileMapPackage.expiration {
                    
  // Check that the mmpk has not expired
  if expiration.isExpired {
   print("The mobile map package has expired")
                        
   switch expiration.expirationType {
   case .allowExpiredAccess:
    print("You can still use this mobile map package.")
    print("Consider obtaining a current, updated version.")
   case .preventExpiredAccess:
    print("The mobile map package cannot be used once expired.")
    return
   }
  }
                    
  // Show when the mobile map package will expire
  if let expiryDate = expiration.dateTime,
   let diffInDays = Calendar.current.dateComponents([.day], from: Date(), to: expiryDate).day {
                        
   print("The mobile map package will expire in ", diffInDays, "days.")
   if expiration.expirationType == .preventExpiredAccess {
    print("You will not be able to use this mobile map package after that time.")
   }
  }
 }
                
 //Access the maps and data

}

Open the offline map

You can open the map directly from a mobile map package file (created by ArcGIS Pro) or from a mobile map package directory (created by the preplanned or on-demand workflows). To create the mobile map package object, pass the mobile map package file path or directory to the AGSMobileMapPackage constructor. Load the mobile map package and obtain a map from its collection of maps. Passing the map to the mapview will initiate loading the map, its layers, and data.

// create a mobile map package from an unpacked mobile map package directory
// or the mobile map package file path
self.mobileMapPackage = AGSMobileMapPackage(fileURL: url)
        
// load the mobile map package (an unpacked mmpk, in this case)
self.mobileMapPackage.load { [weak self] (error: Error?) in
 guard error != nil else {
  print("Error loading mobile map package")
  return
 }
 // Get the first map in the mobile map package and display it in an AGSMapView
 let map = self?.mobileMapPackage.maps.first
 self?.mapView.map = map
}

After loading the map, its metadata is accessible using the AGSMap.item property. In some situations, you may want to access the metadata from the mobile map package without loading the map itself. You can access this from the MobileMapPackage.item property.

See Display a map for more details on how to access and display maps stored in mobile map packages.

Next steps

After you have loaded and opened the mobile map package, you can continue to work with the maps and follow these steps:

  1. Display and interact with the maps, layers, and data offline. Explore and edit the feature data, if necessary.
  2. Update an offline map by synchronizing your edits with the online services when connectivity is restored.
  3. Finish using an offline map to unregister any geodatabases and fully release all locks on the mobile map package.