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:
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;
}));
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)
With Swith 4.1 you must declare your callbacks method @objc public
!!!
@objc public func onSBEventLocationAuthorization(_ event:SBEventLocationAuthorization) {
SBManager.shared().startMonitoring()
print(event)
}
@objc public func onSBEventPerformAction(_ event:SBEventPerformAction) {
print(event)
}
@objc public func onSBEventRegionEnter(_ event:SBEventRegionEnter) {
print(event)
}
@objc public func onSBEventRegionExit(_ event:SBEventRegionExit) {
print(event)
}
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.
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.
To get started with the Sensorberg SDK, sign up for a free account Read more about our Beacon Management Platform
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", "~> {{ site.latestiOSRelease }}"
end
Now you can install the dependencies in your project:
pod install
open <YourProjectName>.xcworkspace
Import the SensorbergSDK
# import <SensorbergSDK/SensorbergSDK.h>
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
.
[[SBManager sharedManager] setApiKey:kAPIKey delegate:self];
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.
[SBManager sharedManager] requestLocationAuthorization:YES];
SBManager.sharedManager().requestLocationAuthorization(true)
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:
[[SBManager sharedManager] bluetoothAuthorization] //returns SBBluetoothStatus
SBManager.sharedManager().bluetoothAuthorization() //returns SBBluetoothStatus
The SDK also includes convenience methods to request the user to turn the Bluetooth radio on:
[[SBManager sharedManager] requestBluetoothAuthorization];
SBManager.sharedManager().requestBluetoothAuthorization()
To be informed when there’s a change in the Bluetooth radio status, SUBSCRIBE to SBEventBluetoothAuthorization:
SUBSCRIBE(SBEventBluetoothAuthorization)
{
if (event.bluetoothAuthorization==SBBluetoothOn)
{
NSLog(@"Bluetooth ON, starting monitoring");
[[SBManager sharedManager] startMonitoring];
}
else
{
NSLog(@"Bluetooth OFF, stopping monitoring");
[[SBManager sharedManager] stopMonitoring];
}
}
@objc public 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:
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];
}
@objc public 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.
- (instancetype)init
{
if (self = [super init])
{
REGISTER();
}
return self;
}
or
- (void)viewDidLoad
{
[super viewDidLoad];
REGISTER();
}
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 is available on CocoaDocs.
The Sensorberg SDK 2.1.3 requires iOS 8.0 and uses:
If you need any technical support, please file an issue at our GitHub repository or contact our support.
Let us know how we can support you with developing awesome applications that include iBeacon functionality. Just drop us a message.
If you encounter any bugs, please report them.
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!