3. ARGSession

ARGSession maintains status of your application and manages the life cycle of your application according to the status. Also, it contains rendered frame.

<ARGear/ARGear.h> should be imported beforehand.

3.1 Init & Create

After creating ARGConfig with API information, ARGSession can be initialized with ARGConfig.

Below is the sample code to create ARGSession.

Objective-C
Swift
Objective-C
// Sample Code. ARGSession Creation Example
ARGConfig *argConfig = [[ARGConfig alloc] initWithApiURL:API_HOST apiKey:API_KEY secretKey:API_SECRET_KEY authKey:API_AUTH_KEY];
NSError * error;
_argSession = [[ARGSession alloc] initWithARGConfig:argConfig error:&error];
_argSession.delegate = self;
Swift
// Sample Code. ARGSession Creation Example
do {
let config = ARGConfig(
apiURL: API_HOST,
apiKey: API_KEY,
secretKey: API_SECRET_KEY,
authKey: API_AUTH_KEY
)
argSession = try ARGSession(argConfig: config)
argSession?.delegate = self
} catch let error as NSError {
} catch let exception as NSException {
}

Unless properly setting ARGConfig during ARGSession creation, ARGear SDK will not be initiated. Therefore, you must create an account in https://argear.io, set the created API Key information in ARGConfig, and create ARGSession with the ARGConfig to use ARGear SDK.

3.2 Run

Create ARGSession with or without an option, ARGInferenceOption. For the details of ARGInferenceOption, please refer to ARGInferenceOption.

A sample code is written below.

Objective-C
Swift
Objective-C
// Sample Code. ARGSession Run Example
ARGSession *argSession = [[ARGSession alloc] initWithARGConfig:argConfig error:&error];
// Without Option Settings
[argSession run];
// With Option Settings
ARGInferenceOption inferenceOption = ARGInferenceOptionFaceTracking | ARGInferenceOptionFaceLandmark2D;
[argSession runWithInferenceConfig:inferenceOption];
Swift
// Sample Code. ARGSession Run Example
// Without Option Settings
argSession?.run()
// With Option Settings
let inferenceFeature: ARGInferenceFeature? = [.faceTracking , .faceLandmark2D]
argSession?.run(withInferenceConfig: inferenceFeature!)

3.3 Pause

To pause the current ARGSession, call pause function inside ARGSession.

A sample code is written below.

Objective-C
Swift
Objective-C
// Sample Code. ARGSession Pause Example
ARGSession *argSession = [[ARGSession alloc] initWithARGConfig:argConfig error:&error];
[argSession pause];
Swift
// Sample Code. ARGSession Pause Example
argSession?.pause()

3.4 Destroy

To destroy the current ARGSession, destroy function in ARGSession will do for you.

A sample code is written as follows.

Objective-C
Swift
Objective-C
// Sample Code. ARGSession Destroy Example
ARGSession *argSession = [[ARGSession alloc] initWithARGConfig:argConfig error:&error];
[argSession destroy];
Swift
// Sample Code. ARGSession Destroy Example
argSession?.destroy()