Skip To Content ArcGIS for Developers Sign In Dashboard

Update an offline map

Offline maps can be created either using ArcGIS Pro or the ArcGIS Runtime SDKs. Their ability to accept updates depends on how the original map is authored (for example, scheduled updates are enabled) and how the mobile map package is created (with ArcGIS Runtime or ArcGIS Pro). The following update options are available:

  • Take a map offline - ArcGIS Pro - the geodatabases in this offline map are read-only and cannot be updated. In this case you need to recreate the mobile map package and redeploy it to all devices.
  • Take a map offline - on-demand - the geodatabases in this offline map can be updated by synchronization with feature services.
  • Take a map offline - preplanned - the geodatabases in this offline map can be updated by synchronization with feature services or by applying scheduled update files.

Synchronize or apply scheduled updates

The offline map sync task is used to perform both synchronization and applying scheduled updates to offline maps.

  1. Create the AGSOfflineMapSyncTask from a map created by the on-demand or preplanned workflows.

    //get the task
    self.offlineMapSyncTask = AGSOfflineMapSyncTask(map: self.map)

  2. Retrieve the task's AGSOfflineMapUpdateCapabilities to identify which update strategy the offline map supports (sync or scheduled updates).

    // Get the update capabilities         
    self.offlineMapUpdateCapabilities = self.offlineMapSyncTask.updateCapabilities
    if (self?.offlineMapUpdateCapabilities?.supportsScheduledUpdatesForFeatures)! {
       print("Supports Scheduled updates")
     }  else if (self?.offlineMapSyncTask.updateCapabilities?.supportsSyncWithFeatureServices)! {
       print("synchronization with feature services")
     }

  3. Determine whether there are any updates available by calling the task's checkForUpdatesWithCompletion method.
    • If the map supportsScheduledUpdatesForFeatures then you can examine the downloadAvailability on the AGSOfflineMapUpdatesInfo object. If there are downloads available then you can check to see how large the download is using the scheduledUpdatesDownloadSize. You can use this information to determine whether you want to download updates immediately - for example based on available disk space or network availability.
    • If the map supportsSyncWithFeatureServices you can examine the uploadAvailability to see if the offline map has any edits to upload. If so go to Step 4. It is not possible to determine whether there are online changes to download without performing a full feature synchronization.
    // Are there any updates available?
    self.offlineMapSyncTask.checkForUpdates {[weak self] (offlineMapUpdatesInfo, error) in
     if let error = error {
      print(error.localizedDescription)
      return
     }
     guard offlineMapUpdatesInfo != nil else {
      print("No offline map updates info")
      return
     }
                
     //Are there any downloads available?
     switch offlineMapUpdatesInfo!.downloadAvailability {
      case .available:
       print("There are online edits available for download")
       print("The download size will be ", offlineMapUpdatesInfo?.scheduledUpdatesDownloadSize, " bytes")
      case .none:
       print("No online edits to download")
      case .indeterminate:
       print("It is not possible to determine whether there are edits to download")
     }
      
     //Are there any uploads available?          
     switch offlineMapUpdatesInfo!.uploadAvailability {
      case .available:
       print("There are local edits available to upload")
      case .none:
       print("No local edits to upload")
      case .indeterminate:
       print("It is not possible to determine whether there are edits to upload")
     }
    }
  4. Obtain the default offline map sync parameters using the defaultOfflineMapSyncParameters method. Override any of these parameters, as required. For example, if resources are limited you may want to overwrite the sync direction to just Upload local edits to the online service.
  5. Create the offline map sync job, offlineMapSyncJob using the offline map sync parameters and run it.
  6. Upon completion check the AGSOfflineMapSyncResult for any errors.
  7. If supportsScheduledUpdatesForFeatures then determine whether the mobile map file needs to be reopened by examining the mobileMapPackageReopenRequired property on the AGSOfflineMapUpdatesInfo object. If so then close the offline map before reopening it.

    //get the default parameters
    self.offlineMapSyncTask.defaultOfflineMapSyncParameters{ [weak self] 
     (params: AGSOfflineMapSyncParameters?, error: Error?) in
     if let error = error {
      print(error)
     } else {
      self?.parameters = params
      //set any parameters as required
     }
    }
    
    //instantiate the sync job the parameters
    self.offlineMapSyncJob = self.offlineMapSyncTask?.offlineMapSyncJob(with: self.parameters)
    
    //start the job
    self.offlineMapSyncJob.start(statusHandler: {[weak self] (status) in
     print("Status [\(String(describing: self?.offlineMapSyncJob.progress.fractionCompleted))]: \(status)")}, 
     completion: { (result, error) in
      if let error = error {
       print(error)
       return
      }
      guard let result = result as? AGSOfflineMapSyncResult else {return}
      if result.hasErrors {
       //... process the errors
      }
      else {
       print("Update complete")
       if result.mobileMapPackageReopenRequired {
        //Close and reopen the mobile map package
       } 
      }
     }
    })

Next

When you have finished working with the mobile map package ensure that you release its maps, layers, and geodatabases before closing or terminating the application. See Finish using an offline map for more details.