Quickstart - Objective-C¶
Complete the steps described on this page, and in about five minutes you'll have integrated the Pulse SDK in your own application.
Set up your campaign first before you integrate the SDK in your application.
Installation¶
Follow this guide to install the SDK. You can either
- install the SDK by linking the framework into your project folder
- use Pods to install the SDK into your Xcode workspace.
Install the SDK manually
Install the SDK by adding the PulseSDK.framework file to the project under "Embedded Binaries"
Install the SDK through Pod
Put the following text in your Pod.file.
platform :ios, '8.0'
target 'Your-target-name' do
pod 'PulseSDK', :git => 'https://pxidev@bitbucket.org/pxiiosteam/pulse-ios-sdk-pod.git', :tag => "3.1"
end
Replace the tag value with the latest repository version provided by Pulse.
Configure your Xcode project
For handling permission of location services, add the following code in your Info.plist
<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
Import framework file in your AppDelegate.h file.
For manual installation
#import <PulseSDK/PulseSDK.h>
Enable Location updates, Bluetooth LE and Background fetch options under Project Capabilities:
If you are using UserNotifications in iOS 10, import the following code in AppDelegate.h file
@import UserNotifications;
@interface AppDelegate : UIResponder <UNUserNotificationCenterDelegate>
@property (strong, nonatomic) UNUserNotificationCenter *center;
Initialization
To initialize the SDK use the setConfig method with your app key within the didFinishLaunchingWithOptions method in the AppDelegate.m file:
//key will be provided by Pulse
NSDictionary* config=@{@"url":@"your-endpoint-url",@"key":@"your-app-key-here"};
[[PulseSDK sharedClient] setConfig:config];
Notifications
In order to receive notifications, you will need to implement delegate methods. As iOS 10 has introduced UserNotification, our SDK can support the new delegate of UNNotificationCenter and the delegate of UINotification for devices not updated to iOS 10.
- iOS 9
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
//app was in background and user clicked on local alert notification to bring app in foreground
[[PulseSDK sharedClient] loadViewOnNotificationClick:notification startSdkForeground:YES StartSdkBackground:YES];
}
- iOS 10
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
//app was in background and user clicked on local alert notification to bring app in foreground
[[PulseSDK sharedClient] loadViewOnUNNotificationClick:response.notification startSdkForeground:YES StartSdkBackground:YES];
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
//app was in foreground
[[PulseSDK sharedClient] loadViewOnUNNotificationClick:notification startSdkForeground:YES StartSdkBackground:YES];
}
Running modes¶
The SDK can run under four different behaviours. In this section, you will learn how to configure them.
Running in Foreground, Background, and Terminated modes.
In this mode, in didFinishLaunchingWithOptions, the method startMonitoringStartSdk has two YES parameters.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//key and url will be provided by Pulse
NSDictionary* config=@{@"url":@"your-endpoint-url",@"key":@"your-app-key-here"};
[[PulseSDK sharedClient] setConfig:config];
if([[[UIDevice currentDevice] systemVersion] floatValue]<10){
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification* notification=[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[[PulseSDK sharedClient]appLaunchedByClickOnNotification:notification startSdKForeground:YES StartSdkBackground:YES];
}
else
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:YES];
}
//for ios 10 or greater
else{
self.center=[UNUserNotificationCenter currentNotificationCenter];
self.center.delegate = self;
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:YES];
}
return YES;
}
Running in Foreground and Background modes.
In this mode, in didFinishLaunchingWithOptions, the method startMonitoringStartSdk has foreground parameter YES and background parameter NO. In applicationDidEnterBackground, the method startSdk has two YES parameters.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//key and url will be provided by Pulse
NSDictionary* config=@{@"url":@"your-endpoint-url",@"key":@"your-app-key-here"};
[[PulseSDK sharedClient] setConfig:config];
if([[[UIDevice currentDevice] systemVersion] floatValue]<10){
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification* notification=[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[[PulseSDK sharedClient]appLaunchedByClickOnNotification:notification startSdKForeground:YES StartSdkBackground:NO];
}
else
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:NO];
}
//for ios 10 or greater
else{
self.center=[UNUserNotificationCenter currentNotificationCenter];
self.center.delegate = self;
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:NO];
}
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application{
[[PulseSDK sharedClient] setForegroundMode:YES backgroundMode:YES];
}
Running in Foreground and Terminated modes.
In this mode, in didFinishLaunchingWithOptions, the method startMonitoringStartSdk has two YES parameters. In applicationDidEnterBackground, the method startSdk has foreground parameter YES background parameter NO.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//key and url will be provided by Pulse
NSDictionary* config=@{@"url":@"your-endpoint-url",@"key":@"your-app-key-here"};
[[PulseSDK sharedClient] setConfig:config];
if([[[UIDevice currentDevice] systemVersion] floatValue]<10){
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification* notification=[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[[PulseSDK sharedClient]appLaunchedByClickOnNotification:notification startSdKForeground:YES StartSdkBackground:YES];
}
else
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:YES];
}
//for ios 10 or greater
else{
self.center=[UNUserNotificationCenter currentNotificationCenter];
self.center.delegate = self;
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:YES];
}
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application{
[[PulseSDK sharedClient] setForegroundMode:YES backgroundMode:NO];
}
Running in Foreground mode.
In this mode, in didFinishLaunchingWithOptions, the method startMonitoringStartSdk has foreground parameter YES background parameter NO.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//key and url will be provided by Pulse
NSDictionary* config=@{@"url":@"your-endpoint-url",@"key":@"your-app-key-here"};
[[PulseSDK sharedClient] setConfig:config];
if([[[UIDevice currentDevice] systemVersion] floatValue]<10){
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification* notification=[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[[PulseSDK sharedClient]appLaunchedByClickOnNotification:notification startSdKForeground:YES StartSdkBackground:NO];
}
else
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:NO];
}
//for ios 10 or greater
else{
self.center=[UNUserNotificationCenter currentNotificationCenter];
self.center.delegate = self;
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:YES StartInBackground:NO];
}
return YES;
}
Running in Background and Terminated mode.
In this mode, in didFinishLaunchingWithOptions, the method startMonitoringStartSdk has foreground parameter NO background parameter YES.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//key and url will be provided by Pulse
NSDictionary* config=@{@"url":@"your-endpoint-url",@"key":@"your-app-key-here"};
[[PulseSDK sharedClient] setConfig:config];
if([[[UIDevice currentDevice] systemVersion] floatValue]<10){
if ([launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification* notification=[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[[PulseSDK sharedClient]appLaunchedByClickOnNotification:notification startSdKForeground:NO StartSdkBackground:YES];
}
else
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:NO StartInBackground:YES];
}
//for ios 10 or greater
else{
self.center=[UNUserNotificationCenter currentNotificationCenter];
self.center.delegate = self;
[[PulseSDK sharedClient] startMonitoringStartSdkForeground:NO StartInBackground:YES];
}
return YES;
}
Session ID¶
When the SDK is first installed, it will automatically create a session ID consisting of a 32 char hexadecimal string.
If you want to specify the session ID, simply call setSessionId with your preferred session ID. This method will start a new session of the user on the Pulse platform.
[[PulseSDK sharedClient] setSessionId:@"your-session-id"];
To update session ID, simply call updateSessionId with your preferred session ID.
This method will update the session id of the user on the Pulse platform.
[[PulseSDK sharedClient] updateSessionId:@"your-session-id"];
Geocode¶
The SDK provides a method to transform addresses into coordinates
[PulseSDK sharedClient] geocode:(NSString *) completionHandler:^(CLLocationCoordinate2D, NSError *)completionHandler
Calculate Distance¶
The SDK provides a method to calculate the distance between two CLLocation objects.
[PulseSDK sharedClient] getDistanceFrom:(CLLocation *) to:(CLLocation *)]