Note about SDK versions

Starting with v2.5, the Sensorberg SDK uses a different API end-point. If you're using v2.4.1 of our SDK, you will need to manually inform the SDK the address of the new end-point: Objective-C
PUBLISH(({  
SBEventUpdateResolver *updateEvent = [SBEventUpdateResolver new];  
updateEvent.baseURL = @"https://portal.sensorberg-cdn.com";  
updateEvent.interactionsPath    = @"/api/v2/sdk/gateways/{apiKey}/interactions.json";  
updateEvent.analyticsPath       = @"/api/v2/sdk/gateways/{apiKey}/analytics.json";  
updateEvent.settingsPath        = @"/api/v2/sdk/gateways/{apiKey}/settings.json?platform=ios";  
updateEvent.pingPath            = @"/api/v2/sdk/gateways/{apiKey}/active.json";  
updateEvent;  
}));   
Swift
let eventUpdateResolver = SBEventUpdateResolver()
eventUpdateResolver.baseURL = "https://portal.sensorberg-cdn.com"
eventUpdateResolver.interactionsPath = "/api/v2/sdk/gateways/{apiKey}/interactions.json"
eventUpdateResolver.analyticsPath = "/api/v2/sdk/gateways/{apiKey}/analytics.json"
eventUpdateResolver.settingsPath = "/api/v2/sdk/gateways/{apiKey}/settings.json?platform=ios"
eventUpdateResolver.pingPath = "/api/v2/sdk/gateways/{apiKey}/active.json"
Tolo.sharedInstance().publish(eventUpdateResolver)

Getting started with the Sensorberg SDK

This is a guide to help developers get up to speed with Sensorberg iOS SDK. These step-by-step instructions are written for Xcode 7, using the iOS 8 SDK. If you are using a previous version of Xcode, you may want to update before starting.

Demo app

Clone the Repository from our GitHub.
Or runing pod try SensorbergSDK in a terminal will open the Sensorberg demo project.
Select the SBDemoApp target and run on device.

Quickstart

1. Create an account

To get started with the Sensorberg SDK, sign up for a free account Read more about our Beacon Management Platform

2. Cocoapods

The easiest way to integrate the iOS SDK is via CocoaPods. If you’re new to CocoaPods, visit their getting started documentation.

cd your-project-directory
pod init
open -a Xcode Podfile

Once you’ve initialized CocoaPods, just add the Sensorberg Pod pod to your target:

target 'YourApp' do
	pod "SensorbergSDK", "~> 2.5"
end

Now you can install the dependencies in your project:

pod install
open <YourProjectName>.xcworkspace

3. Using the SDK

Import the SensorbergSDK

ObjC :

# import <SensorbergSDK/SensorbergSDK.h>

Swift :

import SensorbergSDK

Setup the SBManager with an API key and a delegate You can find your API key on the Beacon Managerment Platform in the “Apps” section. The Sensorberg SDK uses an event bus for events dispatching. During setup, you pass the class instance that will receive the events as the delegate.

ObjC :

[[SBManager sharedManager] setApiKey:kAPIKey delegate:self];

Swift :

SBManager.sharedManager().setApiKey(kAPIKey, delegate: self)

Before starting the scanner, we need to ask permission to use the Location services. If you want to receive events while the app is innactive, you need to pass YES to the requestLocationAuthorization. If you pass NO, the app will receive events only when active.

ObjC :

[SBManager sharedManager] requestLocationAuthorization:YES];

Swift :

SBManager.sharedManager().requestLocationAuthorization(true)

Important

Be sure to add the `NSLocationAlwaysUsageDescription` (or `NSLocationWhenInUseUsageDescription`) key to your plist file and the corresponding string to explain to the user why the app requires access to location.

Keep in mind that the SDK also requires the Bluetooth radio to be turned ON. You can check the status of the radio by calling:

ObjC :

[[SBManager sharedManager] bluetoothAuthorization] //returns SBBluetoothStatus
 

Swift :

SBManager.sharedManager().bluetoothAuthorization() //returns SBBluetoothStatus
The SDK also includes convenience methods to request the user to turn the Bluetooth radio on:  

ObjC :

[[SBManager sharedManager] requestBluetoothAuthorization];

Swift :

SBManager.sharedManager().requestBluetoothAuthorization()  

To be informed when there’s a change in the Bluetooth radio status, SUBSCRIBE to SBEventBluetoothAuthorization:

ObjC :

SUBSCRIBE(SBEventBluetoothAuthorization)
{
    if (event.bluetoothAuthorization==SBBluetoothOn)
    {
        NSLog(@"Bluetooth ON, starting monitoring");
        [[SBManager sharedManager] startMonitoring];
    }
    else
    {
        NSLog(@"Bluetooth OFF, stopping monitoring");
        [[SBManager sharedManager] stopMonitoring];
    }
}

Swift :

func onSBEventBluetoothAuthorization(event:SBEventBluetoothAuthorization)
{
    if (event.bluetoothAuthorization == SBBluetoothOn)
    {
	    print("Bluetooth ON, starting monitoring")
        SBManager.sharedManager().startMonitoring()
    } 
    else
    {
	    print("Bluetooth OFF, stopping monitoring")
        SBManager.sharedManager().stopMonitoring()
    }
}

Once you setup the API key and the SDK starts monitoring, SUBSCRIBE to SBEventPerformAction:

ObjC :

SUBSCRIBE(SBEventPerformAction)
{
	UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.alertTitle = event.campaign.subject;
    notification.alertBody = event.campaign.body;
	notification.alertAction = event.campaign.trigger == kSBTriggerEnter ? @"Enter" : @"Exit";
	notification.alertAction = event.campaign.trigger == kSBTriggerEnterExit ? @"Enter&Exit" : notification.alertAction;
    if (event.campaign.fireDate)
    {
        notification.fireDate = event.campaign.fireDate;
    }
    else
    {
	    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
    }

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

}

Swift :

func onSBEventPerformAction(event:SBEventPerformAction)
{
    let notification = UILocalNotification()
    notification.alertTitle = event.campaign.subject
    notification.alertBody = event.campaign.body
    notification.alertAction = event.campaign.trigger == kSBTriggerEnter ? "Enter" : "Exit"
    notification.alertAction = event.campaign.trigger == kSBTriggerEnterExit ? "Enter&Exit" : notification.alertAction
        
    if (event.campaign.fireDate != nil)
    {
        notification.fireDate = event.campaign.fireDate
    }
    else
    {
        notification.fireDate = NSDate.init(timeIntervalSinceNow: 1)
    }
        UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

Check out the documentation for a list of all supported protocols.

To receive events in other class instances besides the delegate, the listener object has to be registered on Event Bus like following example.

ObjC :

- (instancetype)init
{
    if (self = [super init])
    {
        REGISTER();
    }
    
    return self;
}

or

- (void)viewDidLoad
{
    [super viewDidLoad];
	REGISTER();
}

Swift :

required init()
{
    Tolo.sharedInstance().subscribe(self)
}

or

override func viewDidLoad()
{
    super.viewDidLoad()
    Tolo.sharedInstance().subscribe(self)
} 

Copy & paste the above code in your app exactly as it is (do not replace the apiKey string with your API key - the SDK will do that automatically when you set it up.

Documentation

Documentation is available on CocoaDocs.

Blog Posts

Sample Application on AppStore

Dependencies

The Sensorberg SDK 2.1.3 requires iOS 8.0 and uses:

Support

If you need any technical support, please file an issue at our GitHub repository or contact our support.

Commercial Support

Let us know how we can support you with developing awesome applications that include iBeacon functionality. Just drop us a message.

Bugs

If you encounter any bugs, please report them.

Dependency collisions?

If you have a dependency collision or you don´t want to integrate the sources of our SDK into your project, contact us. We have a script which generates a "mangled" library, with obfuscated symbols.We only recommend to use it in very rare cases!

</br> </br> </br> </br>