subscribeToVisitEvents

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

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

Return

A FlowSubscription; call close() to stop.

Parameters

onEvent

Called for each AFGeofenceEvent.

onError

Called if collection fails.