subscribeToEvents

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()

Swift

let sub = AFCore.shared.facilities().subscribeToEvents { event in
if let entered = event as? AFGeofenceEvent.Entered {
self.handleEnter(entered.geofenceId)
}
}
// Later: sub.close()

Return

A FlowSubscription — call FlowSubscription.close to stop.

Parameters

onEvent

Callback invoked for each AFGeofenceEvent.

onError

Callback invoked if the event collection fails.