subscribeToEvents

abstract fun subscribeToEvents(onEvent: (SmartWalkingEvent) -> Unit, onError: (Throwable) -> Unit = {}): FlowSubscription

Subscribes to SmartWalking lifecycle events (sync progress, permission changes, background delivery triggers).

Call FlowSubscription.close to stop receiving events.

Kotlin

val sub = AFCore.smartWalking().subscribeToEvents(
onEvent = { event ->
when (event) {
is SmartWalkingEvent.SyncSubmitted -> println("Accepted by server (jobId=${event.jobId})")
is SmartWalkingEvent.SyncProcessed -> println("Sync done: data is queryable now")
is SmartWalkingEvent.SyncFailed -> println("Sync failed: ${event.message}")
else -> {}
}
},
onError = { error -> println("Error: ${error.message}") }
)
// Later: sub.close()

Swift

let sub = AFCore.shared.smartWalking().subscribeToEvents(
onEvent: { event in
if let processed = event as? SmartWalkingEvent.SyncProcessed {
print("Sync done — refreshing UI (jobId=\(processed.jobId))")
}
},
onError: { error in print("Error: \(error)") }
)
// Later: sub.close()

Return

A FlowSubscription — call FlowSubscription.close to stop.

Parameters

onEvent

Callback invoked for each SmartWalkingEvent.

onError

Callback invoked if the event collection fails.