GARSession Class

Stay organized with collections Save and categorize content based on your preferences.
GARSession Class Reference

Overview

ARCore 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. See categories of this class for other features. Each feature must be turned on by using |setConfiguration:error:| prior to use.

Inherits NSObject.

Instance Method Summary

(void) - setAuthToken:
 Provide an auth token to use when authenticating with Google Cloud Services. More...
 
(void) - setConfiguration:error:
 Sets the configuration for the session. More...
 
(nullable GARFrame *) - update:error:
 Updates the GARSession with an ARFrame. More...
 
(void) - removeAnchor:
 Removes an anchor from the session. More...
 
(nullable GARAnchor *) - hostCloudAnchor:error:
 Hosts a new Cloud Anchor based on an ARAnchor. More...
 
(nullable GARAnchor *) - hostCloudAnchor:TTLDays:error:
 This will create a new Cloud Anchor with a given lifetime in days, using the transform of the provided anchor. More...
 
(GARFeatureMapQuality) - estimateFeatureMapQualityForHosting:error:
 Estimates the quality of the visual features seen by ARCore in the preceding few seconds and visible from the provided camera transform. More...
 
(nullable GARAnchor *) - resolveCloudAnchorWithIdentifier:error:
 Resolves a Cloud Anchor with a given identifier. More...
 
(BOOL) - isGeospatialModeSupported:
 Determines whether the given geospatial mode is supported on the current device and OS version. More...
 
(nullable GARAnchor *) - createAnchorWithCoordinate:altitude:eastUpSouthQAnchor:error:
 Creates a Geospatial anchor at the specified geodetic location and orientation relative to the Earth. More...
 
(nullable GARAnchor *) - createAnchorWithCoordinate:altitudeAboveTerrain:eastUpSouthQAnchor:error:
 Creates a Terrain anchor at the specified geodetic location, altitude relative to the horizontal position’s terrain and orientation relative to the Earth. More...
 

Class Method Summary

(nullable instancetype) + sessionWithAPIKey:bundleIdentifier:error:
 Creates a GARSession with an API key and bundle identifier. More...
 
(nullable instancetype) + sessionWithError:
 Creates a GARSession. 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

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

Creates a GARSession with an API key and bundle identifier.

Parameters
apiKeyYour API key for Google Cloud Services.
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.
+ (nullable instancetype) sessionWithError: (NSError **)  error

Creates a GARSession.

To authenticate with Google Cloud Services, use setAuthToken:.

Parameters
errorOut parameter for an NSError. Possible errors: GARSessionErrorCodeDeviceNotCompatible - this device or OS version is not currently supported.
Returns
The new GARSession, or nil if there is an error.
- (void) setAuthToken: (NSString *)  authToken

Provide an auth token to use when authenticating with Google Cloud Services.

If the session was created with an API Key, the token will be ignored and an error will be logged. Otherwise, the most recent valid auth token passed in will be used. Call this method each time you refresh your token.

Parameters
authTokenToken to use when authenticating with Google Cloud Services. This must be a nonempty ASCII string with no spaces or control characters. This will be used until another token is passed in. See documentation for supported token types.
- (void) setConfiguration: (GARSessionConfiguration *)  configuration
error: (NSError **)  error 

Sets the configuration for the session.

Parameters
configurationThe new configuration to use.
errorOut param for an NSError.
- (nullable GARFrame *) 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.
- (nullable GARAnchor *) 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. GARSessionErrorCodeIllegalState - current cloud anchor mode is disabled.
Returns
The new GARAnchor, or nil if there is an error.

Provided by category GARSession(CloudAnchors).

- (nullable GARAnchor *) hostCloudAnchor: (ARAnchor *)  anchor
TTLDays: (NSInteger)  TTLDays
error: (NSError **)  error 

This will create a new Cloud Anchor with a given lifetime in days, using the transform of the provided anchor.

The cloud state of the returned anchor will be set to GARCloudAnchorStateTaskInProgress and the initial transform will be set to the transform of the provided anchor. However, the returned anchor is completely independent of the original anchor, and the two transforms might diverge over time.

Hosting requires an active session for which the tracking state is ARTrackingStateNormal, as well as a working internet connection. ARCore will continue to retry silently in the background if it is unable to establish a connection to the ARCore Cloud Anchor service.

Parameters
anchorThe ARAnchor with the desired transform to be used to create a hosted Cloud Anchor.
TTLDaysThe lifetime of the anchor in days. Must be positive. The maximum allowed value is 1 if using an API Key to authenticate with the ARCore Cloud Anchor service, otherwise the maximum allowed value is 365.
errorOut parameter for an NSError. Possible errors: GARSessionErrorCodeInvalidArgument - invalid (nil) anchor or invalid TTL. GARSessionErrorCodeNotTracking - bad current ARTrackingState. GARSessionErrorCodeResourceExhausted - tried to create too many Cloud Anchors. GARSessionErrorCodeIllegalState - current cloud anchor mode is disabled.
Returns
The new GARAnchor, or nil if there is an error.

Provided by category GARSession(CloudAnchors).

- (GARFeatureMapQuality) estimateFeatureMapQualityForHosting: (simd_float4x4)  transform
error: (NSError **)  error 

Estimates the quality of the visual features seen by ARCore in the preceding few seconds and visible from the provided camera transform.

Cloud Anchors hosted using higher quality features will generally result in easier and more accurately resolved Cloud Anchor transforms.

Parameters
transformThe camera transform to use in estimating the quality.
errorOut parameter for an NSError. Possible errors: GARSessionErrorCodeNotTracking - bad current ARTrackingState. GARSessionErrorCodeIllegalState - current cloud anchor mode is disabled.
Returns
The estimated quality of the visual features seen by ARCore in the preceding few seconds and visible from the provided camera transform.

Provided by category GARSession(CloudAnchors).

- (nullable GARAnchor *) 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. You don’t need to wait for a call to resolve a Cloud Anchor to complete before initiating another call. A session can be resolving up to 20 Cloud Anchors at a given time. 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. GARSessionErrorCodeResourceExhausted - tried to create too many Cloud Anchors. GARSessionErrorCodeIllegalState - current cloud anchor mode is disabled.
Returns
The new GARAnchor, or nil if there is an error.

Provided by category GARSession(CloudAnchors).

- (BOOL) isGeospatialModeSupported: (GARGeospatialMode)  geospatialMode

Determines whether the given geospatial mode is supported on the current device and OS version.

If this returns NO, then configuring the session with the given geospatial mode will fail with the error code GARSessionErrorCodeConfigurationNotSupported. A device may be incompatible with a given mode due to insufficient sensor capabilities.

Parameters
geospatialModeThe geospatial mode.
Returns
YES if the geospatialMode is supported, NO otherwise.

Provided by category GARSession(Geospatial).

- (nullable GARAnchor *) createAnchorWithCoordinate: (CLLocationCoordinate2D)  coordinate
altitude: (CLLocationDistance)  altitude
eastUpSouthQAnchor: (simd_quatf)  eastUpSouthQAnchor
error: (NSError **)  error 

Creates a Geospatial anchor at the specified geodetic location and orientation relative to the Earth.

Latitude and longitude are defined by the WGS84 specification, and altitude values are defined as the elevation above the WGS84 ellipsoid in meters.

The rotation provided by eastUpSouthQAnchor is a rotation with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.

To create an anchor that has the +Z axis pointing in the same direction as heading obtained from GARGeospatialTransform, use the following formula:

{qx, qy, qz, qw} = {0, sin((pi - heading * pi / 180.0) / 2), 0, cos((pi -
heading * pi / 180.0) / 2)}}.

An anchor's GARAnchor.trackingState will be GARTrackingStatePaused while GAREarth is GARTrackingStatePaused. The tracking state will permanently become GARTrackingStateStopped if the GARSession configuration is set to GARGeospatialModeDisabled.

Creating anchors near the north pole or south pole is not supported. If the latitude is within 0.1° of the north pole or south pole (90° or -90 °), this function will output GARSessionErrorCodeInvalidArgument and the anchor will fail to be created.

Parameters
coordinateThe latitude and longitude associated with the location, specified using the WGS84 reference frame. This must not be within .1° of the North or South pole (i.e. +- 90°).
altitudeAltitude in reference to the WGS 84 ellipsoid, in meters. Positive values indicate altitudes above approximate sea level. Negative values indicate altitudes below approximate sea level.
eastUpSouthQAnchorRepresents the quaternion from the anchor to East-Up-South (EUS) coordinates (i.e., +X points East, +Y points up, and +Z points South).
errorOut param for an NSError. Possible error codes: GARSessionErrorCodeIllegalState - current geospatial mode is disabled. GARSessionErrorCodeInvalidArgument - latitude is not within range.
Returns
The new anchor, or nil if there was an error.

Provided by category GARSession(Geospatial).

- (nullable GARAnchor *) createAnchorWithCoordinate: (CLLocationCoordinate2D)  coordinate
altitudeAboveTerrain: (CLLocationDistance)  altitudeAboveTerrain
eastUpSouthQAnchor: (simd_quatf)  eastUpSouthQAnchor
error: (NSError **)  error 

Creates a Terrain anchor at the specified geodetic location, altitude relative to the horizontal position’s terrain and orientation relative to the Earth.

Terrain means the ground, or ground floor inside a building with VPS coverage.

The specified altitudeAboveTerrain is interpreted to be relative to the Earth's terrain (or floor) at the specified latitude/longitude geodetic coordinates, rather than relative to the WGS-84 ellipsoid. Specifying an altitudeAboveTerrain of 0 will position the anchor directly on the terrain (or floor) whereas specifying a positive altitudeAboveTerrain will position the anchor above the terrain (or floor), against the direction of gravity.

This function schedules a task to resolve the anchor's pose using the given parameters. You may resolve multiple anchors at a time, but a session cannot be tracking more than 40 Terrain Anchors at time. Attempting to resolve more than 40 Terrain Anchors will result in 'GARSessionErrorCodeResourceExhausted'.

If this function returns error nil, the terrain anchor's GARAnchor.terrainState will be GARTerrainAnchorStateTaskInProgress, and its tracking state will be GARTrackingStatePaused. This anchor remains in this state until its pose has been successfully resolved. If the resolving task results in an error, the tracking state will be set to GARTrackingStateStopped.

Latitude and longitude are defined by the WGS84 specification, and altitude values are defined as the elevation above the WGS84 ellipsoid in meters.

The rotation provided by eastUpSouthQAnchor is a rotation with respect to an east-up-south coordinate frame. An identity rotation will have the anchor oriented such that X+ points to the east, Y+ points up away from the center of the earth, and Z+ points to the south.

To create an anchor that has the +Z axis pointing in the same direction as heading obtained from GARGeospatialTransform, use the following formula:

{qx, qy, qz, qw} = {0, sin((pi - heading * pi / 180.0) / 2), 0, cos((pi -
heading * pi / 180.0) / 2)}}.

An anchor's GARAnchor.trackingState will be GARTrackingStateTracking while GAREarth is GARTrackingStatePaused. The tracking state will permanently become GARTrackingStateStopped if the GARSession configuration is set to GARGeospatialModeDisabled.

Creating anchors near the north pole or south pole is not supported. If the latitude is within 0.1° of the north pole or south pole (90° or -90°), this function will output GARSessionErrorCodeInvalidArgument and the anchor will fail to be created.

Parameters
coordinateThe latitude and longitude associated with the location, specified using the WGS84 reference frame. This must not be within .1° of the North or South pole (i.e. +- 90°).
altitudeAboveTerrainAltitude above Earth's terrain, in meters.
eastUpSouthQAnchorRepresents the quaternion from the anchor to East-Up-South (EUS) coordinates (i.e., +X points East, +Y points up, and +Z points South).
errorOut param for an NSError. Possible error codes: GARSessionErrorCodeIllegalState - current geospatial mode is disabled. GARSessionErrorCodeInvalidArgument - latitude is not within range. GARSessionErrorCodeResourceExhausted - tried to create too many Terrain Anchors.
Returns
The new anchor, or nil if there was an error.

Provided by category GARSession(Geospatial).

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.