subscribe To Events
abstract fun subscribeToEvents(onEvent: (AFGeofenceEvent) -> Unit, onError: (Throwable) -> Unit = {}): FlowSubscription
Subscribes to geofence transition events for monitored facilities.
Events are emitted when the device enters, exits, or dwells in a facility's geofence region. Call FlowSubscription.close to stop receiving events.
Requires startMonitoring to be called first.
Kotlin
val sub = AFCore.facilities().subscribeToEvents { event ->
when (event) {
is AFGeofenceEvent.Entered -> handleEnter(event.geofenceId)
is AFGeofenceEvent.Exited -> handleExit(event.geofenceId)
is AFGeofenceEvent.Dwell -> handleDwell(event.geofenceId)
else -> {}
}
}
// Later: sub.close()Content copied to clipboard
Swift
let sub = AFCore.shared.facilities().subscribeToEvents { event in
if let entered = event as? AFGeofenceEvent.Entered {
self.handleEnter(entered.geofenceId)
}
}
// Later: sub.close()Content copied to clipboard
Return
A FlowSubscription — call FlowSubscription.close to stop.
Parameters
on Event
Callback invoked for each AFGeofenceEvent.
on Error
Callback invoked if the event collection fails.