GARSession Class

GARSession Class Reference

Overview

ARCore Cloud Anchors session class.

Adds ARCore features to an app using ARKit. All NSError's returned by methods in this class have domain GARSessionErrorDomain and code a value of GARSessionErrorCode - see GARSessionError.h. For Augmented Faces, see GARAugmentedFaceSession.

Inherits NSObject.

Instance Method Summary

(GARFrame *_Nullable) - update:error:
 Updates the GARSession with an ARFrame. More...
 
(void) - removeAnchor:
 Removes an anchor from the session. More...
 
(GARAnchor *_Nullable) - hostCloudAnchor:error:
 Hosts a new Cloud Anchor based on an ARAnchor. More...
 
(GARAnchor *_Nullable) - resolveCloudAnchorWithIdentifier:error:
 Resolves a Cloud Anchor with a given identifier. More...
 

Class Method Summary

(instancetype _Nullable) + sessionWithAPIKey:bundleIdentifier:error:
 Creates a GARSession with an API key and bundle identifier. More...
 

Property Summary

GARFramePaircurrentFramePair
 The most recent frame pair, containing the most recent ARFrame passed into update:error: and the corresponding returned GARFrame. More...
 
id< GARSessionDelegatedelegate
 The delegate for receiving callbacks about the GARSession. More...
 
dispatch_queue_t delegateQueue
 The dispatch queue on which the delegate receives calls. More...
 

Method Detail

+ (instancetype _Nullable) sessionWithAPIKey: (NSString *)  apiKey
bundleIdentifier: (NSString *_Nullable)  bundleIdentifier
error: (NSError **)  error 

Creates a GARSession with an API key and bundle identifier.

Parameters
apiKeyYour API key for the ARCore Cloud Anchor service.
bundleIdentifierThe bundle identifier associated to your API key. If nil, defaults to [[NSBundle mainBundle] bundleIdentifier].
errorOut parameter for an NSError. Possible errors: GARSessionErrorCodeDeviceNotCompatible - this device or OS version is not currently supported. GARSessionErrorCodeInvalidArgument - API key is nil or empty.
Returns
The new GARSession, or nil if there is an error.
- (GARFrame *_Nullable) update: (ARFrame *)  frame
error: (NSError **)  error 

Updates the GARSession with an ARFrame.

Call this method with every ARFrame to keep the sessions synced. Can be called on any thread. Normally, this should be called from your ARSessionDelegate's session:didUpdateFrame: method.

Parameters
frameThe next ARFrame from ARKit.
errorOut parameter for NSError. Possible errors: GARSessionErrorCodeInvalidArgument - invalid (nil) frame. GARSessionErrorCodeFrameOutOfOrder - frame has a smaller timestamp than previous.
Returns
The GARFrame corresponding to the ARFrame passed in, or nil if there is an error.
- (void) removeAnchor: (GARAnchor *)  anchor

Removes an anchor from the session.

Parameters
anchorThe anchor to remove.
- (GARAnchor *_Nullable) hostCloudAnchor: (ARAnchor *)  anchor
error: (NSError **)  error 

Hosts a new cloud anchor based on an ARAnchor.

The new anchor will have a cloud state of GARCloudAnchorStateTaskInProgress and its initial transform will be set to that of the passed-in anchor. However, the two transforms may differ over time.

Parameters
anchorThe ARAnchor to host.
errorOut parameter for an NSError. Possible errors: GARSessionErrorCodeInvalidArgument - invalid (nil) anchor. GARSessionErrorCodeNotTracking - bad current ARTrackingState. GARSessionErrorCodeResourceExhausted - tried to create too many Cloud Anchors.
Returns
The new GARAnchor, or nil if there is an error.
- (GARAnchor *_Nullable) resolveCloudAnchorWithIdentifier: (NSString *)  identifier
error: (NSError **)  error 

Resolves a Cloud Anchor with a given identifier.

The new anchor is immediately added to the session and returned, but without a valid transform. If resolving fails, the anchor will be automatically removed from the session.

Parameters
identifierThe Cloud Anchor identifier for the anchor.
errorOut parameter for an NSError. Possible errors: GARSessionErrorCodeInvalidArgument - invalid (nil or empty) identifier. GARSessionErrorCodeNotTracking - bad current ARTrackingState. GARSessionErrorCodeResourceExhausted - tried to create too many Cloud Anchors.
Returns
The new GARAnchor, or nil if there is an error.

Property Detail

- (GARFramePair*) currentFramePair
readatomicassign

The most recent frame pair, containing the most recent ARFrame passed into update:error: and the corresponding returned GARFrame.

- (id<GARSessionDelegate>) delegate
readwriteatomicweak

The delegate for receiving callbacks about the GARSession.

- (dispatch_queue_t) delegateQueue
readwriteatomicassign

The dispatch queue on which the delegate receives calls.

If nil, callbacks happen on the main thread.