iOS Framework¶
Setup¶
Drag the CGIBeaconFramework.framework file into your project. Make sure that “Copy items if needed” is enabled and then press Finish.
Adding dependencies¶
The CGIBeaconFramework uses the JavaScriptCore framework internally. This framework must be added to your app in order for the CGIBeaconFramework to work. To add the JavaScriptCore framework, click the project and then click the +-icon under Linked Frameworks and Libraries and then find JavaScriptCore.framework in the list.
Requesting Permissions From User¶
The framework needs to have access to the users location to be able to monitor for beacons and to receive Geofence events. In order to request the users permission to access location you need to add the key NSLocationAlwaysUsageDescription to the info.plist of your application. The value of the property is the text that the user will see when asked for permission. If this property hasn’t been set, the user will never be asked for permission and the framework will return an error.

Minimal Code Example¶
The CGIBPBeaconManager (CGI Beacon Platform Beacon Manager) is the central manager within the CGIBeaconFramework. This is the class that your application will use to initialize the framework and receive events from.
In your AppDelegate.h add the following import:
#import <CGIBeaconFramework/CGIBPBeaconManager.h>
And then create a CGIBPBeaconManager property in the interface declaration:
@property (strong, nonatomic) CGIBPBeaconManager *beaconManager;
You also need to adopt the CGIBPBeaconManagerDelegate in order to respond to events that CGIBPBeaconManager might send you. Add CGIBPBeaconManagerDelegate to the interface declaration line so that it looks like this:
@interface AppDelegate : UIResponder <UIApplicationDelegate, CGIBPBeaconManagerDelegate>
Instanstiate the CGIBPBeaconManager in the application:didFinishLaunchingWithOptions: method in AppDelegate.m:
self.beaconManager = [[CGIBPBeaconManager alloc] initWithAPIKey:@"com.company.app" apiSecret:@"2AC36F92-DBD1-457C-8F38-4C1944DAFA3C" delegate:self active:YES];
APIKey and apiSecret are set on your application in the Administration Interface.
And finally we create methodstubs for the CGIBPBeaconManagerDelegate methods that we want to use:
// Called when something goes wrong inside the framework. Is for example called if the user hasn't allowed the framework to access location data.
-(void)beaconManager:(CGIBPBeaconManager *)beaconManager didFailWithError:(NSError *)error{
NSLog(@"An error happened in the beaconManager: %@", error.description);
}
// Called when the framework starts monitoring for a trigger
-(void)beaconManagerDidStartMonitoring:(CGIBPBeaconManager *)beaconManager{
NSLog(@"The beaconManager successfully started monitoring for a trigger");
}
// Called when a trigger has ben activated in the framework. This is where you handle what should happen depending on what type of action it is.
// e.g. open webpage, show message to the user, etc.
-(void)beaconManager:(CGIBPBeaconManager *)beaconManager handleActions:(NSArray *)actions{
for (CGIBPAction *action in actions) {
NSLog(@"A trigger has been triggered by the beaconManager: %@", action.description);
}
}
Note
If you plan to add a lot of code to handle actions or to interact with the CGIBPBeaconManager we recommend that you create a separate singleton class that manages everything that has to do with the CGIBeaconPlatform.