Quickstart: Create an iOS app with Azure Spatial Anchors, in either Swift or Objective-C
This quickstart covers how to create an iOS app using Azure Spatial Anchors in either Swift or Objective-C. Azure Spatial Anchors is a cross-platform developer service that allows you to create mixed reality experiences using objects that persist their location across devices over time. When you're finished, you'll have an ARKit iOS app that can save and recall a spatial anchor.
You'll learn how to:
- Create a Spatial Anchors account
- Configure the Spatial Anchors account identifier and account key
- Deploy and run on an iOS device
To complete this quickstart, make sure you have:
- A developer enabled macOS machine with Xcode 10+ and CocoaPods installed.
- Git installed via HomeBrew. Enter the following command into a single line of the Terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)". Then, run
brew install git.
- A developer enabled ARKit compatible iOS device.
Create a Spatial Anchors resource
Navigate to the Azure portal.
From the left menu in the Azure portal, select Create a resource.
Search for "Spatial Anchors" in the search bar.
Select Spatial Anchors to open a dialog and select Create.
In the Spatial Anchors Account form:
- Specify a unique resource name.
- Select the subscription to attach the resource to.
- Create a resource group by selecting Create new and name the resource group myResourceGroup and select OK.
A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.
- Select a location (region) where the resource will be placed.
- Select New to begin creating the resource.
After the resource creation has completed successfully, the resource properties can be viewed. Copy the resource's Account ID value into a text editor, as it will be required later.
Under Settings, select Key, and copy into a text editor the Primary key value. This value is the
Account Keyand will be used later.
Open the sample project
Use the Terminal to perform the following actions.
Clone the samples repository by running the following command:
git clone https://github.com/Azure/azure-spatial-anchors-samples.git
Install the necessary pods using CocoaPods:
pod install --repo-update to install the CocoaPods for the project.
Now open the
.xcworkspace in Xcode.
Configure account identifier and key
The next step is to configure the app to use your account identifier and account key. You copied them into a text editor when setting up the Spatial Anchors resource.
SpatialAnchorsAccountKey field and replace
Set me with the account key.
SpatialAnchorsAccountId field and replace
Set me with the account identifier.
Deploy the app to your iOS device
Connect the iOS device to the Mac and set the active scheme to your iOS device.
Select Build and then run the current scheme.
If you see a
library not found for -lPods-SampleObjC error, you likely opened the
.xcodeproj file instead of the
.xcworkspace. Open the
.xcworkspace and try again.
In Xcode, stop the app by pressing Stop.
Clean up resources
In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group.
From the left menu in the Azure portal, select Resource groups and then select myResourceGroup.
On the resource group page, make sure that the listed resources are the ones you want to delete.
Select Delete, type myResourceGroup in the text box, and then select Delete.
In this quickstart, you've created a Spatial Anchors account. You then configured and deployed an App to save and recall Spatial Anchors. To learn more about how to improve the App so that it can share Spatial Anchors with other devices, continue to the next tutorial.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.