iOS Quickstart
A quick guide for installing, initializing, and authenticating users
Installation
The first step to any integration is installing the BrandMessenger framework.
Our preferred installation method is Cocoapods. You can find detailed steps for doing so in the Automated Installation Using Cocoapods guide.
One you have installed the framework using CocoaPods, add the code snippet below in the application's Podfile and run pod install
.
source 'https://github.com/CocoaPods/Specs'
use_frameworks! # Required to add
platform :ios, '12.0' # Required to add
target 'TARGET_NAME' do
pod 'BrandMessenger', :git => 'https://github.com/lithiumtech/ios-brandmessenger-sdk-dist.git', :tag => '0.1.0'
# Required to add
end
Authentication
Prior to sending the first message, the user requires authentication. This is a two-step process.
First, initialize the SDK with the Company Key and App ID as shown below. Contact Khoros Support for your Company Key and App ID if you do not have them.
@import BrandMessengerUI
// Call it only once in your app.
[[BrandMessengerManager alloc] initWithCompanyKey: @"<COMPANY KEY>", applicationKey: @"<APP ID>"];// Replace this with your Company Key and App ID
import BrandMessengerUI
// Call it only once in your app.
BrandMessengerManager(companyKey: "<COMPANY KEY>", applicationKey: "<APP ID>") // Replace this with your Company Key and App ID
Custom Base URLs
You might want to set region-based URLs before the init method. Also, there is a different way available to initialize the SDK depending on the widget-id instead of the application key. Refer to the docs here for more details
Next, register the user following the example below.
[BrandMessengerManager login:@"accessToken" completion:^(KBMRegistrationResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"BrandMessenger login failed with an error: %@", error.localizedDescription);
return;
}
NSLog(@"BrandMessenger login successful");
}];
BrandMessengerManager.login("accessToken") { response, error in
if let err = error {
print("BrandMessenger login failed with an error: ", err.localizedDescription)
return
}
print("BrandMessenger login successful")
}
Login as anonymous user Or with JWT
You can also log in as an anonymous user or log in with a JWT token instead of an access token. Refer to the docs here
The logged-in user can then open a conversation with an agent.
[BrandMessengerManager show:viewController];
// or
[BrandMessengerManager show:nil];
BrandMessengerManager.show(viewController)
// or
BrandMessengerManager.show()
This will present the conversation screen from the supplied viewController, or if not provided, will look for the top view controller and present from there.
To receive app notifications Push notification setup is required.
Updated about 2 months ago