Instantiate the GeoMoby SDK¶
The GeoMoby SDK should be initialised in the appDelegate class to work separately from all views, so you can change views in your app and this will not affect the GeoMoby SDK.
In AppDelegate.h, import the GeoMoby SDK and declare the GeomobyDelegate interface -
#import <Geomoby/Geomoby.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, GeomobyDelegate>
In AppDelegate.m, initialize the GeoMoby SDK -
/*************************
* Objective-C
*************************/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// GeoMoby initialisation
NSDictionary *tags = @{
@"gender" : @"female",
@"age" : @"25",
@"membership" : @"gold"
};
// First usage of class should be createInstance
[[Geomoby alloc] initWithAppKey:@"XXXXXXXX"];
[[Geomoby sharedInstance] setDevMode:true];
[[Geomoby sharedInstance] setUUID:@"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"];
[[Geomoby sharedInstance] setSilenceWindowStart:23 andStop:5];
[[Geomoby sharedInstance] setTags:tags];
[[Geomoby sharedInstance] setDelegate:self];
// GeoMoby start
[[Geomoby sharedInstance] start];
// Getting ready with Significant Location Changes
[self updateOnSignificantLocation:launchOptions];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[Geomoby sharedInstance] applicationDidEnterBackground];
[[Geomoby sharedInstance] updateFences];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
[[Geomoby sharedInstance] applicationWillEnterForeground];
}
/** The below code should be implemented in your project in order to unlock Significant Location Changes **/
// Dealing with significant location updates
- (void)updateOnSignificantLocation: (NSDictionary *) userDict {
if (userDict && [userDict objectForKey: UIApplicationLaunchOptionsLocationKey]) {
[[Geomoby sharedInstance] applicationDidEnterBackground];
[[Geomoby sharedInstance] updateFences];
}
}
/*************************
* Swift
*************************/
override func viewDidLoad() {
super.viewDidLoad()
self.initGeomoby()
self.setGeomobyTags()
}
func initGeoMoby() {
let application = UIApplication.shared
let delegate = application.delegate as? AppDelegate
let geomoby = Geomoby(appKey: geomobyKey)
geomoby?.setUUID(UIDevice.current.identifierForVendor?.uuidString)
geomoby?.setDevMode(true)
geomoby?.setDelegate(delegate)
geomoby?.getFences()
// Start the GeoMoby SDK
Geomoby.sharedInstance()?.start()
}
func applicationDidEnterBackground(_ application: UIApplication) {
if Geomoby.isInitialised(){
Geomoby.sharedInstance()?.applicationDidEnterBackground()
Geomoby.sharedInstance()?.updateFences()
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
if Geomoby.isInitialised(){
Geomoby.sharedInstance()?.applicationWillEnterForeground()
}
}
/** The below code should be implemented in your project in order to unlock Significant Location Changes **/
// Dealing with significant location updates
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.updateOnSignificationLocation(launchOptions: launchOptions)
[...]
}
func updateOnSignificationLocation(launchOptions: [UIApplicationLaunchOptionsKey: Any]?) {
if let launchOptions = launchOptions, let _ = launchOptions[.location]{
if !Geomoby.isInitialised(){
let geomoby = Geomoby.init(appKey: geomobyKey )
geomoby?.setDelegate(self)
geomoby?.start()
}
Geomoby.sharedInstance()?.updateFences()
Geomoby.sharedInstance()?.applicationDidEnterBackground()
}
}
tags and setTags - tags are fully customisable key/value pairs which can capture key demographic data about the app user. This can then be used to set and evaluate conditions on when an event can fire.
initWithAppKey - initialize the library with your application key (can be found on the GeoMoby Application Settings page)
setDevMode - enable or disable logs
setUUID - set a beacon UUID filter
setSilenceWindowStart andStop - set silence window (time when users shouldn’t receive any notifications)
setDelegate - set callbacks delegate (in our case - self object)
Note: [[Geomoby alloc] initWithAppKey] returns a Geomoby object. You can access Geomoby using [Geomoby sharedInstance] or via your own Geomoby object.
/*************************
* Objective-C
*************************/
Geomoby *geomoby = [[Geomoby alloc] initWithAppKey:@”XXXXXXXX”];
/*************************
* Swift
*************************/
let geomoby = Geomoby.init(appKey: geomobyKey )
You can check if the GeoMoby service is initialised. Use [Geomoby isInitialised] for it. This method is available starting version 2.6.11.27.
You can check the GeoMoby SDK version using [Geomoby version].
Some additional public methods:
-(void)updatedInitLocation:(CLLocation *)location; // contains first location after start service
-(void)updatedCurrentLocation:(CLLocation *)location; // contains current location of user
-(void)updatedInterval:(int)interval; // contains the value of the location update period
-(void)updatedFenceList:(NSArray*)fences; // confirms completion of fence list update
-(void)updatedDistanceToNearestFence:(double)distance inside:(int)flag; // contains value of distance to nearest fence
-(void)updatedSpeed:(float)speed; // contains device speed
-(void)updatedGPSAccuracy:(float)acuracy; // contains updated GPS accuracy