subscribe To Visit Events
abstract fun subscribeToVisitEvents(onEvent: (AFGeofenceEvent) -> Unit, onError: (Throwable) -> Unit = {}): FlowSubscription
Subscribes to visitEvents with callbacks - the Swift-friendly form.
Use it from Swift, or from Kotlin code outside a coroutine - it replaces facilities().subscribeToEvents(). Callbacks run on a background thread; hop to the main thread before touching UI. Keep the returned subscription and close it when the screen goes away.
Android (Kotlin)
val subscription = AFCore.locations().subscribeToVisitEvents(
onEvent = { event -> runOnUiThread { render(event) } }
)
// Later: subscription.close()Content copied to clipboard
iOS (Swift)
subscription = AFCore.shared.locations().subscribeToVisitEvents(
onEvent: { event in
Task { @MainActor in
if let entered = event as? AFGeofenceEvent.Entered {
showArrived(entered.geofenceId)
}
}
},
onError: { _ in }
)
// Later: subscription?.close()Content copied to clipboard
Return
A FlowSubscription; call close() to stop.
Parameters
on Event
Called for each AFGeofenceEvent.
on Error
Called if collection fails.