Skip to content

Configure and start the SDK Objective C

zioolek edited this page May 4, 2017 · 1 revision

Configure and start the SDK - Objective-C

  1. In your AppDelegate.m file add the following statement: #import <UbuduSDK/UbuduSDK.h>

  2. Add this to you didFinishLaunchingWithOptions: method. You need to replace the app namespace by the one you created on the Ubudu manager platform.

[UbuduSDK sharedInstance].appNamespace = @"634b207ee2f313c109c58675b44324ac2d41e61e";
[UbuduSDK sharedInstance].delegate = self;
NSError *error = nil;
BOOL started = [[UbuduSDK sharedInstance] start:&error];
if (!started) {
    NSLog(@"UbuduSDK start error: %@", error);
}

The delegate is the object which will be receiving all the notifications via callbacks defined in the UbuduSDKDelegate protocol. This might be your AppDelegate for example.

  1. To allow to the SDK to work as expected (automatic execution of the actions other than "notifications", i.e. open a web page) you need to implement the UIKit callback application:didReceiveLocalNotification: like this:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    [[UbuduSDK sharedInstance] executeLocalNotificationActions:notification];
}

Stop the SDK

If you want the SDK to stop running then call:

[[UbuduSDK sharedInstance] stop];

Stopping the SDK will stop it from updating location and tracking geofences and beacons. It will also prevent your app from being awaken by the system (you will not have background support after that).

Full code example

Here is a full example on how to initialize and start the SDK:

// AppDelegate.m

#import <UbuduSDK/UbuduSDK.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [UbuduSDK sharedInstance].appNamespace = @"634b207ee2f313c109c58675b44324ac2d41e61e";
    [UbuduSDK sharedInstance].delegate = self;
    /* Optionally, provide the ID of your user so we can link the Ubudu user with the IDs of your information system. */
    //[UbuduSDK sharedInstance].user = [[UbuduUser alloc] initWithID:@"Your client ID" withProperties:@{@"foo_property":@"bar_value"}];
    NSError *error = nil;
    BOOL started = [[UbuduSDK sharedInstance] start:&error];
    if (!started) {
        NSLog(@"UbuduSDK start error: %@", error);
    }
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    [[UbuduSDK sharedInstance] executeLocalNotificationActions:notification];
}