Appearance
SDK Initialization
How to initialize the Upshot.ai iOS SDK in your application.
Overview
You should initialize the Upshot.ai 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.
Import Upshot Module
To access Upshot.ai classes in your project, you need to import Upshot.
How to import?
objc
@import Upshot;
swift
import Upshot
Initialize Upshot.ai
There are multiple options that can be set/modified while initializing the SDK based on your application preferences and utilization of various system resources.
Parameters:
- 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
- BKExceptionHandler: Enabling this option allows Upshot.ai to capture crash logs and send it to the servers. This option is enabled by default.
How to Initialize?
objective-c
NSDictionary *options = @{
BKApplicationID: @"Application Id given by Upshot.ai",
BKApplicationOwnerID: @"Owner Id given by Upshot.ai",
BKFetchLocation: @YES,
BKExceptionHandler: @YES
};
[[BrandKinesis sharedInstance] initializeWithOptions:options delegate:self];
swift
let options = [
BKApplicationID: "Application Id given by Upshot.ai",
BKApplicationOwnerID: "Owner Id given by Upshot.ai",
BKFetchLocation: true,
BKExceptionHandler: true
] as [String : Any]
BrandKinesis.sharedInstance().initialize(options: options, delegate: self)
Authentication Delegate
Implement the authentication delegate to handle initialization status:
objective-c
// In your AppDelegate.h or ViewController.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, BrandKinesisDelegate>
// In your AppDelegate.m or ViewController.m
- (void)brandKinesisAuthentication:(BrandKinesis*)brandKinesis withStatus:(BOOL)status error:(NSError *)error {
}
swift
// In your AppDelegate.swift or ViewController.swift
class AppDelegate: UIResponder, UIApplicationDelegate, BrandKinesisDelegate {
func brandKinesisAuthentication(_ brandKinesis:BrandKinesis, withStatus status:Bool, error:Error?) {
}
}
Run Your Application
On Upshot.ai SDK integration success, you can see an active user on the dashboard LiveEvents 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.
Where to terminate Upshot.ai?
On applicationDidEnterBackground
terminate Upshot.ai
How to terminate?
objective-c
[[BrandKinesis sharedInstance] terminate];
swift
BrandKinesis.sharedInstance().terminate()
App Lifecycle Integration
Foreground Initialization
Initialize the SDK when the app comes to foreground:
objective-c
- (void)applicationDidBecomeActive:(UIApplication *)application {
// App has come to the foreground
[[BrandKinesis sharedInstance] initializeWithOptions:options delegate:self];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// App has gone to the background
[[BrandKinesis sharedInstance] terminate];
}
swift
func applicationDidBecomeActive(_ application: UIApplication) {
// App has come to the foreground
let options = [
BKApplicationID: "Application Id given by Upshot.ai",
BKApplicationOwnerID: "Owner Id given by Upshot.ai",
BKFetchLocation: true,
BKExceptionHandler: true
] as [String : Any]
BrandKinesis.sharedInstance().initialize(options: options, delegate: self)
}
func applicationDidEnterBackground(_ application: UIApplication) {
// App has gone to the background
BrandKinesis.sharedInstance().terminate()
}
Best Practices
- Initialize early in app lifecycle (AppDelegate)
- Always implement authentication delegate before initialization
- Handle app state changes for proper session management
- Terminate sessions when app goes to background
- Use environment-specific configurations
- Avoid multiple initializations during app navigation
Troubleshooting
Common initialization issues and solutions:
Invalid Credentials
- Verify App ID and Owner ID from Upshot.ai dashboard
- Check environment configuration
- Confirm account status on dashboard
Authentication Failures
- Check network connectivity
- Verify API endpoint accessibility
- Review authentication response error messages
- Ensure proper delegate setup before initialization
Session Issues
- Avoid multiple simultaneous sessions
- Always terminate sessions on app background
- Check session timeout configurations
- Monitor active sessions on dashboard