Initialize Upshot.ai

You should initialize the SDK every time the app is launched or app comes to foreground from background. For every initialization you will get authentication status using upshot authentication delegate. A session is created every time the SDK is initialized

Step1: import Upshot module

To access Upshot.ai classes in your class/project we need to import Upshot.

import Upshot:
@import Upshot;
import Upshot

Step2: Initialize Upshot.ai

Where to initialize Upshot.ai?

Initialize Upshot.ai in two places. onAppLaunch and Application will enter Foreground.

Ways to initialize Upshot.ai?

Initialization can be done in two ways

1. Using ConfigFile:

You can find your config file in the Upshot.ai Dashboard and add it your root project. The fields can be further modified by altering the property values in the JSON file, eg: AppId OwnerId and so on.

UpshotConfig file

Sample Code:
[[BrandKinesis sharedInstance] initializeWithDelegate: self];
BrandKinesis.sharedInstance(). initialize(withDelegate: self)
2. Setting your own properties:

There are multiple options that can be set/modified while initializing the SDK based on your application preferences and utilization of various system resources. All the initialization options for BrandKinesis can be found in BKProperties.h

Below are the list of initialization options and their descriptions

BKApplicationID: Application ID provided by Upshot.ai (can be viewed on dashboard)

BKApplicationOwnerID: Account ID provided by Upshot.ai (can be viewed on dashboard)

BKFetchLocation: By default, BKFetchLocation is disabled. To enable it, set this property to true while initializing BrandKinesis. This will help capture device’s location details

BKUseCellularData: Data can be sent to Upshot.ai through WiFi and/or Cellular data. By default, this option is enabled to allow Upshot.ai to use both Cellular and WIFI to connect with Upshot.ai servers. Set this option to false if only WiFi usage should be allowed.

BKEnableDebugLogs: Logs are disabled by default in the SDK. You can enable it by setting this property to true while initializing BrandKinesis.

BKExceptionHandler: Enabling this option allows Upshot.ai to capture crash logs and send it to the servers. This option is enabled by default.

Sample Code:
NSDictionary *options = @{
BKApplicationID: @"ApplicationId Provided by Upshot.ai",
BKApplicationOwnerID: @"OwnerId Provided by Upshot.ai",
BKFetchLocation: [NSNumber numberWithBool:YES],
BKExceptionHandler: [NSNumber numberWithBool:YES]
};

[[BrandKinesis sharedInstance] initializeWithOptions:options delegate: self];
let options = [
BKApplicationID: "ApplicationId Provided by Upshot.ai",
BKApplicationOwnerID: "OwnerId Provided by Upshot.ai",
BKFetchLocation: true,
BKExceptionHandler: true
] as [String : Any]

BrandKinesis.sharedInstance().initialize(options: options, delegate: self)

Note:

Authentication Delegate:

- (void)brandKinesisAuthentication:(BrandKinesis*)brandKinesis withStatus:(BOOL)status error:(NSError *)error {
}
func brandKinesisAuthentication(_ brandKinesis:BrandKinesis, withStatus status:Bool, error:Error?) {
}

On Authentication success you can validate user record in Upshot.ai dashboard under Live Events Section :



Terminate

By definition, every open app is a session. Hence, when the app goes to background the session should be terminated. And when the app comes back to the foreground, the session should be reinitialized.

Every successful authentication creates a new session. A session is terminated only when a call to terminate function/method is made. Repeated calls to initializeWithOptions: delegate: on the shared instance of BrandKinesis will terminate the existing session and create a new session. Also, you should make sure not to reinitialize the SDK when the user moves from one activity to the other in the same application to avoid multiple (duplicate) sessions being recorded.

Where to terminate Upshot.ai?

on applicationDidEnterBackground terminate Upshot.ai

Sample Code:
[[BrandKinesis sharedInstance] terminate];
BrandKinesis.sharedInstance().terminate()