Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Die ARCore Cloud Anchor API oder der ARCore Cloud Anchor-Dienst bietet Cloud-Anchor-Funktionen für Ihre iOS-Apps, sodass Nutzer sowohl auf iOS- als auch auf Android-Geräten AR-Inhalte teilen können.
In diesem Leitfaden erfahren Sie, wie Sie:
Entwicklungsumgebung für die Verwendung mit Cloud-Anchors einrichten
Ankern und Auflösen in einer Beispiel-App ausprobieren
CocoaPods 1.4.0 oder höher, wenn Sie CocoaPods verwenden
Ein ARKit-kompatibles Apple-Gerät mit iOS 12.0 oder höher (Bereitstellungsziel muss iOS 12.0 oder höher sein)
Cloud-Markierungen verwenden
In den folgenden Schritten wird anhand der Beispiel-App „Cloud Anchors“ gezeigt, wie Sie eine App konfigurieren und erstellen, die ARCore Cloud Anchors unterstützt.
Beispielanwendung für Cloud Anchors abrufen
Klonen Sie das ARCore SDK for iOS aus GitHub oder laden Sie es herunter, um den Code der Beispiel-App zu erhalten.
Öffnen Sie ein Terminal- oder Finderfenster und wechseln Sie zum Ordner, in dem Sie das SDK geklont oder heruntergeladen haben.
Den Code der Beispiel-App finden Sie unter /arcore-ios-sdk-master/Examples/CloudAnchorExample.
Der Code der Beispiel-App für persistente Cloud-Markierungen befindet sich in /arcore-ios-sdk-master/Examples/PersistentCloudAnchorExample.
Sitzungseinrichtung
Die Beispiel-App führt im Rahmen der Sitzungseinrichtung die folgenden wichtigen Aufgaben aus:
ARFrames in der Methode session:didUpdateFrame: an die GARSession übergeben.
Freigabe von Cloud Anchor-IDs einrichten
In der Beispiel-App für Cloud Anchors wird Firebase verwendet, um Cloud Anchor-IDs zwischen Geräten zu teilen. In Ihren eigenen Apps können Sie eine andere Lösung verwenden.
So richten Sie die Firebase-Datenbank in der Beispiel-App ein:
Laden Sie die Datei GoogleService-Info.plist herunter, die beim Hinzufügen von Firebase zu Ihrer App generiert wurde.
Aktivieren Sie Firebase Storage für das Beispiel:
Rufen Sie die Firebase Console auf und wählen Sie das Projekt aus, das Sie für die Beispiel-App eingerichtet haben.
Wählen Sie das Steuerfeld Database aus.
Klicken Sie bei der Option Realtime Database auf Get Started.
Das Menü Security rules for Realtime Database wird geöffnet.
Wählen Sie zum Ausführen des Beispiels Start in test mode aus.
Wenn Sie Firebase für eine App verwenden, die Sie veröffentlichen möchten, sollten Sie strengere Sicherheitsregeln verwenden.
Fügen Sie in Xcode Ihrer App die Datei GoogleService-Info.plist neben Info.plist hinzu.
ARCore API einrichten
Wenn Sie Cloud-Anker verwenden möchten, müssen Sie zuerst die ARCore API für Ihre Anwendung einrichten.
Pod-Update ausführen
Die App CloudAnchorExample wird mit einer Podfile geliefert, die mit den erforderlichen ARCore SDK- und iOS-Versionen vorkonfiguriert ist. So installierst du diese Abhängigkeiten:
Öffnen Sie ein Terminalfenster und führen Sie pod update aus dem Ordner aus, in dem sich das Xcode-Projekt befindet.
Dadurch wird eine .xcworkspace-Datei generiert, mit der Sie die App später erstellen und ausführen können.
Öffnen Sie die .xcworkspace-Datei für das Projekt in Xcode.
Achten Sie darauf, dass Sie die Datei .xcworkspace und nicht die Datei .xcodeproj zum Erstellen verwenden, um Buildfehler zu vermeiden.
App-Bundle-ID ändern
Ändern Sie in Xcode die Bundle-ID der App, damit Sie die App mit Ihrem Team signieren können.
App erstellen und ausführen
Verbinden Sie Ihr Gerät und starten Sie die App in Xcode.
Optional: Wenn Sie die Beispiel-App erstellen und ausführen, finden Sie im folgenden Abschnitt Informationen dazu, wie Sie mit der App Cloud-Markierungen hosten und auflösen.
Beispiel-App ausprobieren
Erstellen und führen Sie die Beispiel-App aus der Datei .xcworkspace aus, um sie auf Ihrem Gerät zu starten.
Gewähren Sie der App bei Aufforderung die Kameraberechtigungen. ARKit beginnt dann, Ebenen vor Ihrer Kamera zu erkennen.
Tippen Sie auf HOST, um den Hostingmodus aufzurufen. Es wird ein Raumcode zum Teilen gehosteter Markierungen generiert und auf dem Bildschirm angezeigt.
Tippen Sie auf ein Flugzeug, um dort einen Cloud-Anchor zu hosten.
Die App platziert ein Andy Android-Objekt auf der Ebene und fügt einen Anker hinzu.
Eine Hostanfrage wird an den Cloud-Endpunkt der ARCore API gesendet. Die Hostanfrage enthält Daten, die die Position des Ankers relativ zu den visuellen Elementen in seiner Nähe darstellen.
Sobald der Anker gehostet wurde, erhält er eine ID, die zum Auflösen von Cloud-Ankern in diesem Gruppenbereich verwendet wird.
Tippen Sie auf RESOLVE und geben Sie einen Raumcode ein, um mit demselben oder einem anderen Gerät auf zuvor gehostete Cloud-Anchors für diesen Raum zuzugreifen.
Eine Auflösungsanfrage wird an den Cloud-Endpunkt der ARCore API gesendet.
Die Auflösungsanfrage enthält eine Cloud-Anchor-ID. Wenn die ID mit einem gehosteten Anker übereinstimmt und die Lokalisierung erfolgreich ist, gibt der Server die Transformation des Ankers in Ihren lokalen Koordinaten zurück.
In der Beispielanwendung wird die Transformation verwendet, um der Szene den Anker hinzuzufügen und daran befestigte virtuelle Objekte zu rendern.
ARCore SDK zu Ihren Apps hinzufügen
In Ihren eigenen Apps müssen Sie Podfile aktualisieren, um das ARCore SDK und die unterstützte iOS-Version einzubinden. Das geht so:
Fügen Sie der Datei Podfile Ihres Projekts die folgenden platform und pod hinzu:
platform :ios, '11.0'
pod 'ARCore/CloudAnchors', '~> 1.50.0'
Öffnen Sie ein Terminalfenster und führen Sie pod update aus dem Ordner aus, in dem sich Ihr Xcode-Projekt befindet.
Dadurch wird eine .xcworkspace-Datei generiert, mit der Sie die App erstellen und ausführen können.
Persistente Cloud-Markierungen
Wie unter Cloud-Anchor mit Persistenz hosten beschrieben, können Sie dem Cloud-Anchor eine Gültigkeitsdauer von bis zu 365 Tagen zuweisen. Beispielcode zur Verwendung persistenter Cloud-Anker ist im Verzeichnis /arcore-ios-sdk-master/Examples/PersistentCloudAnchorExample im ARCore SDK for iOS auf GitHub verfügbar.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-26 (UTC)."],[[["\u003cp\u003eThe ARCore Cloud Anchor API enables shared AR experiences between iOS and Android devices by allowing users to host and resolve cloud anchors.\u003c/p\u003e\n"],["\u003cp\u003eTo use Cloud Anchors, you need Xcode 13.0+, Cocoapods 1.4.0+ (if using), an ARKit-compatible device running iOS 12.0+, and the ARCore SDK for iOS.\u003c/p\u003e\n"],["\u003cp\u003eThe Cloud Anchors sample app demonstrates key tasks like session setup, Cloud Anchor ID sharing via Firebase, and hosting/resolving anchors.\u003c/p\u003e\n"],["\u003cp\u003eYou can add the ARCore SDK to your own iOS apps by updating your Podfile and running \u003ccode\u003epod update\u003c/code\u003e to install the necessary dependencies.\u003c/p\u003e\n"],["\u003cp\u003ePersistent Cloud Anchors can be created with a time-to-live up to 365 days, allowing for longer-lasting shared AR experiences.\u003c/p\u003e\n"]]],[],null,["# Quickstart for Cloud Anchors in iOS\n\nThe **ARCore Cloud Anchor API** , or **ARCore Cloud Anchor service**, provides cloud anchor capabilities for your iOS apps, making it\npossible for users on both iOS and Android devices to share AR experiences.\n\nThis guide shows you how to:\n\n- Set up your development environment to work with Cloud Anchors\n- Try out hosting and resolving anchors in a sample app\n\nPrerequisites\n-------------\n\n- [Xcode](https://developer.apple.com/xcode/) version 13.0 or later\n- [Cocoapods](https://cocoapods.org/) 1.4.0 or later if using Cocoapods\n- An ARKit-compatible Apple device running iOS 12.0 or later (deployment target of iOS 12.0 or later required)\n\n| **Note:** Beginning with ARCore 1.12, all ARKit-compatible devices are supported.\n\nUsing Cloud Anchors\n-------------------\n\nThe following steps use the Cloud Anchors sample app to show you the critical\ntasks for configuring and building an app that supports ARCore Cloud Anchors.\n\n### Get the Cloud Anchors sample app\n\n1. Clone or download the [ARCore SDK for iOS from GitHub](https://github.com/google-ar/arcore-ios-sdk/releases)\n to obtain the sample app code.\n\n2. Open a Terminal or Finder window and navigate to the folder where you cloned\n or downloaded the SDK.\n\n3. You can find the sample app code in \n\n `/arcore-ios-sdk-master/Examples/CloudAnchorExample`.\n\n The [persistent cloud anchors](#persistent-cloud-anchors) sample app code is\n in \n\n `/arcore-ios-sdk-master/Examples/PersistentCloudAnchorExample`.\n\n### Session setup\n\nThe sample app performs the following important tasks as part of setting up the\nsession:\n\n- Creating a [`GARSession`](/ar/reference/ios/interface_g_a_r_session)\n- Creating an [`ARSession`](https://developer.apple.com/documentation/arkit/arsession) and running it\n- Setting an [`ARSessionDelegate`](https://developer.apple.com/documentation/arkit/arsession/2865614-delegate).\n- Passing [`ARFrame`s](https://developer.apple.com/documentation/arkit/arframe) to the `GARSession` in the `session:didUpdateFrame:` method.\n\n### Set up Cloud Anchor ID sharing\n\nThe Cloud Anchors sample app uses Firebase for sharing Cloud Anchor IDs between\ndevices. You can use a different solution in your own apps.\n\nTo set up Firebase database in the sample app:\n\n1. Follow the Firebase instructions for [adding Firebase to your app](https://firebase.google.com/docs/ios/setup).\n2. Download the `GoogleService-Info.plist` file generated as part of adding Firebase to your app.\n3. Enable Firebase storage for the sample:\n - Go to the **Firebase console** and select the project you set up for the sample app.\n - Select the **Database** panel.\n - On the **Realtime Database** option, click **Get Started**.\n - The **Security rules for Realtime Database** menu opens.\n - For purposes of running the sample, select **Start in test mode**.\n - Note that if you are using Firebase for an app that you plan to publish, you should use more restrictive security rules.\n4. In Xcode, add the `GoogleService-Info.plist` file to your app, next to `Info.plist`.\n\n### Set up the ARCore API\n\nTo use Cloud Anchors, you must first set up the\n[**ARCore API**](/ar/develop/authorization?platform=ios) for your application.\n\n### Run pod update\n\nThe **CloudAnchorExample** app ships with a `Podfile` preconfigured with the\nARCore SDK and iOS versions that you'll need. To install these dependencies:\n\n1. Open a Terminal window and run `pod update` from the folder where the Xcode project exists. \n This generates an `.xcworkspace` file that you'll use later to build and run the app.\n\nSee [Add the ARCore SDK to your app](/ar/develop/ios/cloud-anchors-quickstart-ios#add_the_arcore_sdk_to_your_apps)\nfor details on configuring the `Podfile` in your own apps.\n\n1. Open the `.xcworkspace` file for the project in Xcode.\n\n To avoid build errors, make sure you are building from the `.xcworkspace`\n file and not the `.xcodeproj` file.\n\n### Change the app bundle ID\n\nIn Xcode, change the app's bundle ID so that you can sign the app with your team.\n\n### Build and run the app\n\n1. Connect your device and launch the app in Xcode.\n\n2. (Optional) If you are building and running the sample app, see the following\n section for details on using the app to host and resolve Cloud Anchors.\n\n### Try out the sample app\n\n1. Build and run the sample app from the `.xcworkspace` file to launch\n it on your device.\n\n2. If prompted, grant camera permissions to the app. ARKit then\n starts detecting planes in front of your camera.\n\n3. Tap **HOST** to enter hosting mode. A room code for sharing hosted anchors\n is generated and appears on your screen.\n\n4. Tap a plane to start hosting a cloud anchor there.\n\n - The app places an Andy Android object on the plane and attaches an anchor to it.\n - A host request is sent to the ARCore API cloud endpoint. The host request includes data representing the anchor's position relative to the visual features near it.\n - Once the anchor is hosted, it gets an ID that is used for resolving cloud anchors in this space.\n5. Tap **RESOLVE** and enter a room code to access previously\n hosted Cloud Anchors for this room, using the same or a different device. \n\n - A resolve request is sent to the ARCore API cloud endpoint.\n - 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.\n - The sample app uses the transform to add the anchor to your scene and render virtual objects attached to it.\n\nAdd the ARCore SDK to your apps\n-------------------------------\n\nIn your own apps, you'll need to update your `Podfile` to include the\nARCore SDK and supported iOS versioning. To do this:\n\n1. Add the following `platform` and `pod` to your\n project's `Podfile`:\n\n platform :ios, '11.0'\n pod 'ARCore/CloudAnchors', '~\u003e 1.50.0'\n\n| **Note:** To ensure that your project includes the correct ARCore version, **specify\n| all three of the `ARCore` version digits** in your `pod`. For example, use `1.12.0` instead of `1.12`.\n\n1. Open a Terminal window and run `pod update` from the folder where your Xcode project exists. \n This generates an `.xcworkspace` file that you use to build and run the app.\n\nPersistent cloud anchors\n------------------------\n\nAs described in [Host a Cloud Anchor with persistence](https://developers.google.com/ar/develop/ios/cloud-anchors/developer-guide#host-with-persistence),\nyou can give the cloud anchor a time-to-live up to 365 days. Sample code for\nusing persistent cloud anchors is available in the `/arcore-ios-sdk-master/Examples/PersistentCloudAnchorExample`\ndirectory in the [ARCore SDK for iOS from GitHub](https://github.com/google-ar/arcore-ios-sdk/releases).\n\nNext steps\n----------\n\n- See the [Cloud Anchors Developer Guide for iOS](/ar/develop/ios/cloud-anchors/cloud-anchors-developer-guide-ios)\n to explore the sample app code and learn more about working with Cloud Anchors\n in your own apps.\n\n- Review details in the [ARCore iOS API Reference](/ar/reference/ios)."]]