Monitoring Geofences - iOS

This document explains how to set up your app to receive Push notifications via Mapp Cloud when a user is in a location of interest.

Add capability for location update in background mode:

Start monitoring geo-locations, and appropriate methods for that. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41



//this part needs to be added at didFinishLaunchingWithOptions method at AppDelegate class

Appoxee.shared()?.addObserver(self, forKeyPath: "isReady", options: ( NSKeyValueObservingOptions(rawValue: NSKeyValueObservingOptions.new.rawValue | NSKeyValueObservingOptions.old.rawValue)), context: nil)



override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

        if (keyPath == "isReady") {



            Appoxee.shared()?.removeObserver(self, forKeyPath: "isReady")

            

            AppoxeeLocationManager.shared()?.delegate = self

            AppoxeeLocationManager.shared()?.logLevel = 1

            AppoxeeLocationManager.shared()?.enableLocationMonitoring()

        }

    }



//this methods will be triggered if the app is opened while user enter or exit from location

func locationManager(_ manager: AppoxeeLocationManager, didFailWithError error: Error?) {

        NSLog("Location Error:", error.debugDescription)

    }



    func locationManager(_ manager: AppoxeeLocationManager, didExitGeoRegion geoRegion: CLCircularRegion) {

              //perform something on exit event

    }



    func locationManager(_ manager: AppoxeeLocationManager, didEnterGeoRegion geoRegion: CLCircularRegion) {

           //perform something on enter event

    }

To stop geofence call

AppoxeeLocationManager.shared()?.disableLocationMonitoring()

On this page user should enable:

  1. Wi-Fi (user must be connected on Wi-Fi network) 

  2. Location set Always (for specific app user must allows location access always)                    

   

In the screenshots above you can see which options should be enabled when the user is redirected to Location Service in Settings. 

Â