iOS – Geo-triggering

Start Geo-triggering

Geo-triggering allows the automatic detection of location context change events (such as entering or exiting a geofence, or crossing a Geoline™). For this capability, the SDK needs to be initialized and the app must have location permission.

To start geo-triggering, you should

BDLocationManager.instance()?.startGeoTriggering(){ error in
    guard error == nil else {
        print("There was an error starting geo-triggering with the Bluedot SDK: \(error.localizedDescription)")
        return
    }
 }

The startGeoTriggering method should be called when the app is in the foreground. For more information refer to Location modules should be started from the foreground

Receiving Geo-trigger events

Implement BDPGeoTriggeringEventDelegate and register it with BDLocationManager to receive Geo-triggering related callbacks.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    BDLocationManager.instance()?.geoTriggeringEventDelegate = self
    BDLocationManager.instance()?.initialize(
        withProjectId: "MyProjectId"){ error in
            guard error == nil else {
                print("Initialisation with Bluedot SDK failed \(error.localizedDescription)")
                 return
             }
    }
    return true
 }
extension AppDelegate: BDPGeoTriggeringEventDelegate {
    func onZoneInfoUpdate(_ zoneInfos: Set<BDZoneInfo>) {
        print("My local cache of the zones has updated!")
    }
    func didEnterZone(_ enterEvent: BDZoneEntryEvent){ 
        print("I have entered a zone.")
    }
    func didExitZone(_ exitEvent: BDZoneExitEvent) {
        print("I have exited a zone")
    }
 }

Stop Geo-triggering

If you only need geo-triggering for a limited period, once that period is over, you can stop the geo-trigger service.

BDLocationManager.instance()?.stopGeoTriggering(){ error in
    guard error == nil else {
        print("There was an error stopping geo-triggering with the Bluedot SDK: \(error.localizedDescription)")
        return
    }
 }
image

To start Geo-triggering with app restart notification, notification permission must be granted.

Created by Melwin Chiramel on December 21, 2020