ArcGIS Runtime SDK for macOS

Open a mobile scene package from ArcGIS Pro

If your users' devices need to operate in a disconnected or offline capacity, use an offline scene in your ArcGIS Runtime app.

For use in ArcGIS Runtime apps, offline scenes must be created in ArcGIS Pro and saved as mobile scene packages (.mspk files). For information on creating and saving .mspk files in ArcGIS Pro, see Create Mobile Scene Package in the ArcGIS Pro tool reference.

You can distribute .mspk files to your users, for use in your app, by:

  • Uploading and sharing the files in your organization (with ArcGIS Online or your portal)

  • Delivering the files to individual devices through common file sharing methods (network share, email, and so on)

Offline scenes can include basemaps, operational layers, 3D scene layers, tiled layers (.tpk), tables, relationship classes, locators and elevation sources as tiled data. Raster elevation sources are not supported.

For details on using scenes while connected (for viewing, interacting with, and analysis), see Display a scene. This type of scene is known as a web scene.

Open an .mspk file in your app

Most mobile scene packages can be accessed directly by instantiating the AGSMobileScenePackage object from the .mspk file. However, raster data that's an operational or basemap layer cannot be read directly from an .mspk file, so it's recommended you always perform a check. To perform this check, follow the steps below.

  1. Make sure the .mspk file gets added to your users' devices. For example, you can have your users download it from ArcGIS Online or your portal to their device when connected.
  2. Check whether the mobile scene package file supports direct reading by calling the checkDirectReadSupportForMobileScenePackage method.
  3. If the file can be read directly, skip to step 5.
  4. If the file cannot be read directly, then unpack the .mspk file in an output directory. Before unpacking the file, confirm that the device has sufficient space for the file using the device's native API. An unpacked .mspk file occupies a similar amount of space as the original packaged file. After the unpacking operation completes, you can delete the original .mspk file to save space (unless you need the file for another purpose).

    Tip:

    To avoid having to unpack the .mspk file, instead of adding raster data to an .mspk file as an operational or basemap layer, you can create a .tpk file from the raster data and add that to the scene before creating the .mspk file.

  5. Instantiate the AGSMobileScenePackage object from the .mspk file or output directory.
  6. Load the AGSMobileScenePackage.

    Once you have instantiated and loaded the .mspk file, you can access any of its scenes for display.

  7. To display a scene, pass it to the scene view.

    self.mobileScenePackage?.load(completion: {[weak self] (error) in
     let scene = self?.mobileScenePackage?.scene.first
     self?.sceneView.scene = scene
    })

Code sample:

// Check whether the mobile scene package supports direct read
AGSMobileScenePackage.checkDirectReadSupportForMobileScenePackage(atFileURL: mspkFileURL, completion: {[weak self] (canBeReadDirectly, error) in
 //
 // If the mobile scene package supports direct read
 if canBeReadDirectly {
  // Create the mobile scene package object from the .mspk file
  self?.mobileScenePackage = AGSMobileScenePackage(fileURL: mspkFileURL)
  self?.mobileScenePackage?.load(completion: { (error) in
   //...check mobile scene package has loaded
  })
 }
 // 
 // If the mobile scene package file does NOT support direct read
 else {
  // Unpack the mobile scene package file into an output directory
  AGSMobileScenePackage.unpack(atFileURL: mspkFileURL, outputDirectory: mspkDirectoryURL, completion: { (error) in                
   //   
   // Create the mobile scene package object from the output directory
   self?.mobileScenePackage = AGSMobileScenePackage(fileURL: mspkDirectoryURL)
   self?.mobileScenePackage?.load(completion: { (error) in
    //...check mobile scene package has loaded
   })
  })
 }
})