Quickstart for Cloud Anchors in iOS

The ARCore SDK provides cloud anchor capabilities for your iOS apps, making it possible for users on both iOS and Android devices to share AR experiences.

This guide shows you how to:

  • Set up your development environment to work with cloud anchors
  • Try out hosting and resolving anchors in a sample app

Requirements

To use cloud anchors, you'll need:

Hardware

Note that:

  • Because iOS 11 supports only 64-bit architectures, the ARCore SDK for iOS supports only x86_64 and arm64 architectures.

Software

Using cloud anchors

The following steps use the Cloud Anchors sample app to show you the critical tasks for configuring and building an app with cloud anchor capabilities.

Get the Cloud Anchors sample app

  1. Clone or download the ARCore SDK for iOS from GitHub to obtain the sample app code.

  2. Open a Terminal or Finder window and navigate to the folder where you cloned or downloaded the SDK.

  3. You can find the sample app code in
    /arcore-ios-sdk-master/Examples/CloudAnchorExample.

Set up cloud anchor ID sharing

The Cloud Anchors sample app uses Firebase for sharing cloud anchor IDs between devices. You can use a different solution in your own apps.

To set up Firebase storage in the sample app:

  1. Follow the Firebase instructions for adding Firebase to your app.
  2. Download the GoogleService-Info.plist file generated as part of adding Firebase to your app.
  3. Enable Firebase storage for the sample:
    • Go to the Firebase console and select the project you set up for the sample app.
    • Select the Database panel.
    • On the Realtime Database option, click Get Started.
    • The Security rules for Realtime Database menu opens.
      • For purposes of running the sample, select Start in test mode.
      • Note that if you are using Firebase for an app that you plan to publish, you should use more restrictive security rules.
  4. In Xcode, add the GoogleService-Info.plist file to your app, next to Info.plist.

Add an API Key

To use cloud anchors, you'll need to add an API key to the app.

  1. Obtain an API key. See Setting up API keys in the Google Cloud Platform Console Help Center if you are new to working with API keys.

  2. Enable the ARCore Cloud Anchor API for your Google Cloud Platform project.

  3. In Xcode, add your API key to the app. To do this, add the key to the following code in ExampleViewController.m:

    self.gSession = [GARSession sessionWithAPIKey:@"Replace me with your API key."
                                 bundleIdentifier:nil
                                            error:nil];
    

Run pod update

The CloudAnchorExample app ships with a Podfile preconfigured with the ARCore SDK and iOS versions that you'll need. To install these dependencies:

  1. Open a Terminal window and run pod update from the folder where the Xcode project exists.
    This generates an .xcworkspace file that you'll use later to build and run the app.

See Add the ARCore SDK to your app for details on configuring the Podfile in your own apps.

Change the app bundle ID

  1. In Xcode, change the app's bundle ID so that you can sign the app with your team.

  2. Close the .xcodeproj file.

Build and run the app

  1. Open the .xcworkspace file for the project in Xcode.

    To avoid build errors, make sure you are building from the .xcworkspace file and not the .xcodeproj file.

  2. Connect your device and launch the app in Xcode.

  3. (Optional) If you are building and running the sample app, see the following section for details on using the app to host and resolve cloud anchors.

Try out the sample app

  1. Build and run the sample app from the .xcworkspace file to launch it on your device.

  2. If prompted, grant camera permissions to the app. ARKit then starts detecting planes in front of your camera.

  3. Tap HOST to enter hosting mode. A room code for sharing hosted anchors is generated and appears on your screen.

  4. Tap a plane to start hosting a cloud anchor there.

    • The app places an Andy Android object on the plane and attaches an anchor to it.
    • A host request is sent to the ARCore Cloud Anchor service. The host request includes data representing the anchor's position relative to the visual features near it.
    • Once the anchor is hosted, it gets an ID that is used for resolving cloud anchors in this space.
  5. Tap RESOLVE and enter a room code to access previously hosted cloud anchors for this room, using the same or a different device.

    • A resolve request is sent to the ARCore Cloud Anchor service.
    • The resolve request includes a cloud anchor ID. If the ID matches a hosted anchor and localization is successful, the server returns the transform of the anchor in your local coordinates.
    • The sample app uses the transform to add the anchor to your scene and render virtual objects attached to it.

Add the ARCore SDK to your apps

In your own apps, you'll need to update your Podfile to include the ARCore SDK and supported iOS versioning. To do this:

  1. Add the following platform and pod to your project's Podfile:

        platform :ios, '11.0'
        pod 'ARCore', '~> 1.3.0'
    
  2. Open a Terminal window and run pod update from the folder where your Xcode project exists.
    This generates an .xcworkspace file that you use to build and run the app.

Next steps

Send feedback about...