subscribeToLocationSharingEnabled

abstract fun subscribeToLocationSharingEnabled(onState: (Boolean) -> Unit, onError: (Throwable) -> Unit = {}): FlowSubscription

Subscribes to locationSharingEnabled with callbacks - for binding a SwiftUI toggle to the opt-in. Replays the current value, then each change.

Use it from Swift to reflect the opt-in - it replaces the iOS AFCore.shared.subscribeToHeartbeatEnabled. Callbacks run on a background thread; in Swift the value arrives as a KotlinBoolean (read .boolValue).

Android (Kotlin)

val subscription = AFCore.locations().subscribeToLocationSharingEnabled(
onState = { enabled -> runOnUiThread { sharingSwitch.isChecked = enabled } }
)
// Later: subscription.close()

iOS (Swift)

enabledSubscription = AFCore.shared.locations().subscribeToLocationSharingEnabled(
onState: { enabled in
Task { @MainActor in self.isSharing = enabled.boolValue }
},
onError: { _ in }
)
// Later: enabledSubscription?.close()

Return

A FlowSubscription; call close() to stop.

Parameters

onState

Called with the current opt-in, then on each change.

onError

Called if collection fails.