subscribe To Session State
abstract fun subscribeToSessionState(onState: (SessionState) -> Unit, onError: (Throwable) -> Unit = {}): FlowSubscription
Swift-friendly callback wrapper around sessionState. Delivers state updates on the main thread; call FlowSubscription.close to stop receiving updates (e.g. in deinit / viewDidDisappear).
Android/Kotlin consumers should collect sessionState directly with coroutines; this wrapper exists for Swift / Objective-C interop.
iOS (Swift)
let sub = AFCore.shared.authentication().subscribeToSessionState(
onState: { state in
switch state {
case .loggedIn: self.showHome()
case .sessionExpired: self.showLogin("Session expired")
default: self.showLogin()
}
},
onError: { error in print(error) }
)
// Later: sub.close()Content copied to clipboard
Return
A FlowSubscription to cancel the subscription.
Parameters
on State
Called on every SessionState emission, on the main thread.
on Error
Called if collection throws (rare; a StateFlow does not fail).