Skip to main content

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 didUpdateZoneInfo() {
        print("My local cache of the zones has updated!")
    }
    func didEnterZone(_ enterZoneEvent: GeoTriggerEvent){
        print("I have entered a zone.")
    }
    func didExitZone(_ exitZoneEvent: GeoTriggerEvent) {
        print("I have exited a zone")
    }
}
info

Exit events will only trigger when the device has moved a substantial distance away from the geofence. Detection of Exit events may not be as immediate as Entry events.

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
    }
}
info

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