iOS Toolkit¶
The CGI Beacon Toolkit gives you a set of premade implementations for handling the most common action types. With the toolkit you can within minutes have an app that can for example show the user messages and webpages based on location. The iOS toolkit can currently handle the following action types:
Action types | Supported |
---|---|
Show Webpage | Yes (fullscreen, popup, and external) |
Show Message | Yes |
Google Analytics Track Page | Yes |
Google Analytics Track event | Yes |
Setup¶
Adding the CGI Beacon Toolkit to your application is very easy. First drag the CGIBeaconToolkit.framework file into your project. Make sure that that Copy items if needed is selected and then press Finish.
The toolkit uses the CoreBluetooth framework internally and Google Analytics need three more libraries. These dependencies must be added to your app in order for the toolkit to function. To add the frameworks to your app, click the project and then click the +-icon under Linked Frameworks and Libraries in the General tab. Find the libraries in the list below and add them to your project.
- CoreBluetooth.framework
- CoreData.framework
- libz.dylib
- libsqlite3.dylib
The toolkit has Objective-C categories with methods that are being called inside the toolkit. In order for the library to be able to call these methods you need to add the flag “-ObjC” to the linker. Click the project and then press Build Settings. Scroll down to Linking and find the property Other Linker Flags and add the text -ObjC. If you can’t find the property make sure that you switch from Basic to All in the upper left corner of the list.
Minimal Code Example¶
Add the import below to your AppDelegate.h (or wherever you want to handle actions).
#import <CGIBeaconToolkit/CGIBeaconToolkit.h>
Inside the handleActions method where the framework passes the actions for you to handle, add the following lines to let the toolkit handle all the actions that it supports.
CGIBeaconToolkit *toolkit = [CGIBeaconToolkit sharedToolkit];
for (CGIBPAction *action in actions) {
// Always check if the toolkit can handle the action before sending it to the toolkit.
if ([toolkit canHandleAction:action]) {
NSLog(@"Toolkit is handling the action: %@", action.description);
[toolkit handleAction:action];
}
}