I managed to solve this issue. In my scenario it was caused by a race condition in reading the Keychain too early in the app launch. I was checking for an auth token on the keychain within SceneDelegate.scene(_:willConnectTo:options:).
Instead I wait for the keychain protected data to become available like so:
func refreshAuthFromKeychain(_ callback: @escaping (Bool) -> Void) {
/// Avoid race condition where the app might try to access keychain data before the device has decrypted it
guard UIApplication.shared.isProtectedDataAvailable else {
NotificationCenter
.default
.publisher(for: UIApplication.protectedDataDidBecomeAvailableNotification)
.first()
.sink { _ in
self.refreshAuthFromKeychain(callback)
}.store(in: &cancellables)
return
}
....
/// Then load from the keychain
Topic:
Privacy & Security
SubTopic:
General
Tags: