GeoSync¶
The GeoSync feature allows you to request an immediate synchronisation of all your installed devices after making changes to geofence configuration.
Before you can use GeoSync you first need to register a Firebase project in the Firebase Console.
Once your project is registered you can get the server key from the Cloud Messaging tab of the Project Settings pane on the Firebase console -


Enter the server key into the GeoMoby Application Settings.

Add Firebase to your app. To do this you’ll need the Firebase project you registered above and a Firebase configuration file for your app.

Click Add Firebase to your iOS app and follow the setup steps.
When prompted, enter your app’s bundle ID. It’s important to enter the bundle ID your app is using; this can only be set when you add an app to your Firebase project.
At the end, you’ll download a GoogleService-Info.plist file. You can download this file again at any time. If you haven’t done so already, copy this into your Xcode project root.
Generate a Certificate Signing Request (CSR) file on your Mac -
In the Applications folder open the Utilities folder and launch Keychain Access
Within the Keychain Access drop down menu, select Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority.
In the Certificate Information window, enter the following information:
In the User Email Address field, enter your email address.
In the Common Name field, create a name for your private key (e.g., John Doe Dev Key).
The CA Email Address field should be left empty.
In the “Request is” group, select the “Saved to disk” option.
Click Continue within Keychain Access to complete the CSR generating process.
Create an Apple Push Notification certificate in the Apple Developer Member Centre -
Go to Certificates in the left hand menu
Click the + button
For certificate type select ‘Apple Push Notification service’ (development or production as appropriate) and press Continue
Select the id of the app you are developing from the drop-down list and press Continue
Make sure you have your Certificate Signing Request ready (see above) and press Continue
Upload the Certificate Signing Request and press Continue
Download the new certificate
Open Keychain Access, select the new certificate and export it as a PKCS 12 (extension .p12) file
Upload the P12 certificate from the previous step to the Firebase console - Project Settings > Cloud Messaging > iOS app configuration > APNs Certificates > Upload


Add the Firebase/Core and Firebase/Messaging libraries to your project Podfile. Run pod install afterwards to import the libraries -
pod 'Firebase/Core'
pod 'Firebase/Messaging'
Import the Firebase module, configure a shared instance and configure notification settings on application launch after Geomoby initialization (Objective C example shown) -
// Geomoby start
[[Geomoby sharedInstance] start];
// Firebase configure
[FIRApp configure];
[FIRMessaging messaging].delegate = self;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max)
{ // iOS 9 or earlier
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
else
{ // iOS 10 or later
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNAuthorizationOptions authOptions =
UNAuthorizationOptionAlert
| UNAuthorizationOptionSound
| UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];
#endif
}
[[UIApplication sharedApplication] registerForRemoteNotifications];
Add an observer to listen for changes in the token (Objective C example shown) -
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(onTokenRefresh)
name:kFIRInstanceIDTokenRefreshNotification object:nil];
Implement the subscribeTopic method to handle subscription to the topic (Objective C example shown) -
/*************************
* Objective-C
*************************/
- (void)subscribeToTopic
{
[[FIRMessaging messaging] subscribeToTopic:@"/topics/GeomobySync"];
}
/*************************
* Swift
*************************/
static let topicsGeomobySync = "GeomobySync"
func subscribeToTopic() {
Messaging.messaging().subscribe(toTopic: .topicsGeomobySync) { err in
if (err != nil) {
print("ERROR: Subscribing to \(String.topicsGeomobySync) failed. Err:\(err.debugDescription)")
} else {
print("Subscribed to \(String.topicsGeomobySync) .....")
}
}
}
func unsubscribeToTopic() {
Messaging.messaging().unsubscribe(fromTopic: .topicsGeomobySync)
}
Implement the onTokenRefresh method to handle changes in the token (Objective C example shown) -
/*************************
* Objective-C
*************************/
- (void)onTokenRefresh
{
NSString *token = [[FIRInstanceID instanceID] token];
[[Geomoby sharedInstance] updateInstanceId:token];
[self subscribeToTopic];
}
/*************************
* Swift
*************************/
func onTokenRefresh() {
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
#if DEBUG
print("Error fetching remote instange ID: \(error)")
#endif
} else if let result = result {
let isGeomobyInitialized = UserDefaults.standard.bool(forKey: kUserDefaults.isGeomobyInitialized.rawValue)
if isGeomobyInitialized {
let token = result.token
if Geomoby.isInitialised(){
Geomoby.sharedInstance()?.updateInstanceId(token)
}
}
self.subscribeToTopic()
}
}
}
Implement the onMessageReceived method to handle received messages (Objective C example shown) -
/*************************
* Objective-C
*************************/
- (void)onMessageReceived:(NSDictionary *)data
{
if (data[@"MessageType"] && [data[@"MessageType"] isEqualToString:@"GeomobySyncRequest"])
{
[[Geomoby sharedInstance] updateFences];
}
}
/*************************
* Swift
*************************/
func onMessageReceived(data: [AnyHashable : Any]) {
if let messageType = data[String.messageTypeKey] as? String, messageType == .geomobySyncRequest {
if Geomoby.isInitialised(){
Geomoby.sharedInstance()?.updateFences()
}else{
print("Geomoby is NOT initialised and failed to call pdateFences()")
}
}
}
Add and implement the handler for registering for remote notifications (Objective C example shown) -
/*************************
* Objective-C
*************************/
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[self subscribeToTopic];
}
/*************************
* Swift
*************************/
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
subscribeToTopic()
}
Add and implement listeners for incoming push notifications (Objective C example shown) -
/*************************
* Objective-C
*************************/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[self onMessageReceived:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler
{
[self onMessageReceived:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
/*************************
* Swift
*************************/
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
onMessageReceived(data: userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
onMessageReceived(data: userInfo)
}