Skip to content

Tutorial: Save and view scans#

This tutorial covers how to save your scans to the cloud and then access them via the web dashboard.

When you're finished, the app you created in the previous tutorial will be able to save scans.

You'll learn how to:

  • Customize AboundScanController behavior using a delegate.
  • Save your scans along with custom data.
  • View and download your scans using the dashboard.

Requirements#

Before starting, make sure you have the Xcode project you created in the previous tutorial (Get Started.)

This tutorial takes 10 minutes to complete.


Step 1: Create the delegate#

The Abound SDK uses a delegate to communicate with the rest of your app.

You'll need to assign an AboundScanControllerDelegate to your AboundScanController, and then implement it to pass information to the Abound SDK.

Let's start by creating a delegate with a trivial implementation.

  • Open Xcode and then open the project you created in the Get Started tutorial.
  • Open ViewController.swift and add the following code.
ViewController.swift
class ViewController: UIViewController {

    // ...

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let scanController = AboundScanController()
        scanController.instructions = "Scan your space."
        scanController.delegate = self
        present(scanController, animated: true)
    }
}

extension ViewController: AboundScanControllerDelegate {
    func scanController(_ scanController: AboundScanController,
                        shouldSaveScanWithInfo info: [AboundScanController.InfoKey: Any],
                        saveCallback: @escaping ([String: Any]?) -> Void) {
    }

    func scanController(_ scanController: AboundScanController,
                        didFinishScanningWithInfo info: [AboundScanController.InfoKey : Any]) {
        scanController.dismiss(animated: true)
    }

    func scanController(_ scanController: AboundScanController,
                        didFailWithError error: AboundError) {
        print(error)
    }

    func scanControllerDidCancel(_ scanController: AboundScanController) {
        scanController.dismiss(animated: true)
    }
}

Step 2: Implement saving#

When the user captures the scan and taps the Save button, the SDK calls the shouldSaveScanWithInfo delegate method.

The method is passed a saveCallback closure that you must call to tell the SDK whether to keep the scan. You can also pass it any extra information you'd like to store, e.g. your app's custom identifier for the current user. To discard the scan instead, pass nil to the callback.

Let's add a dialog that pops up when the user finishes the scan. We'll ask them to describe what they description and then store that along with the scan.

  • Add the following code to ViewController.swift.
ViewController.swift
extension ViewController: AboundScanControllerDelegate {
    func scanController(_ scanController: AboundScanController,
                        shouldSaveScanWithInfo info: [AboundScanController.InfoKey: Any],
                        saveCallback: @escaping ([String: Any]?) -> Void) {
        let dialog = UIAlertController(title: "Describe this space", message: nil,
                                       preferredStyle: .alert)
        dialog.addTextField()
        dialog.addAction(UIAlertAction(title: "Cancel", style: .cancel) { _ in
            saveCallback(nil)
        })
        dialog.addAction(UIAlertAction(title: "OK", style: .default) { _ in
            saveCallback(["description": dialog.textFields!.first!.text!])
        })
        scanController.present(dialog, animated: true)
    }

    // ...
}

Step 3: Run the app#

You're ready to run the app and save a scan.

Now, whenever you finish a scan, the shouldSaveScanWithInfo method is called, a prompt for a description is shown, and then the scan is uploaded.

The upload is relatively small — a 1,000 sq ft apartment is between 20-50 MB of data — so should finish quickly.

  • Connect your device to your computer and press ⌘R to run the app.
  • Capture your space and enter a description to save.

Step 4: View the scan#

After the scan is uploaded, the data is processed in seconds and made available.

A convenient way to access the data is via the web dashboard.

  • Open your dashboard at dashboard.aboundlabs.com/developer.
  • Click on the app name in API Keys to show the app's scans.
  • Click on the row for the scan you made in the Scans table.
  • To view the scan in 3D, click on the image.
  • To download the 3D textured mesh in OBJ format click on the OBJ button.

Note

If your scan doesn't appear immediately, then wait a minute and then refresh the page.


Next steps#

In this tutorial, you extended your app to save scans.

To learn more about the iOS SDK see the SDK reference.

To learn about how to access the data via the REST API, continue to the next tutorial.


Please send any feedback or suggestions to feedback@aboundlabs.com.