iOS 15 beta wipes out app data

When I open the app after a couple of hours, all of. the app data is getting wiped out (UserDefaults, keychain password).

I'm on iOS 15 public beta 3. Has anyone faced similar issue, or how to debug and get it fixed?

Hello, have you found any solution to this issue? I think I'm experiencing the same.

Thanks

I think I am also experiencing this issue, although it is difficult to verify. I store an auth token on the keychain but have had the app seemingly delete it after a few hours. We are not experiencing this on iOS14.

Hello we experince same on our app we are using keychain to store a token, and in some time it gets wiped out. the check of the presence of the key is failling, but the key is there. is working good in iOS 14

Hi, in which life cycle step do you do these operations? I learned that in iOS15, you should not do anything system and app related in the AppDelegate.init method.

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

Yes, you've to delay the API call for UserDefaults etc. till you receive callback like didFinishLaunching. If you try to access before it, sometimes you may get data and sometimes you may not. Same code was working fine in iOS14 and below.

My customers who installed ios 15.0(iPhone 11) & 15.0.1(iPhone 12 pro) have the same problems with UserDefaults which had been wiped out a few hours later after the launch of the app.

And of course, it's after "didFinishLaunching" and I try to retrieve it several times at different timing.

I don't know if it is related to the other issue. https://developer.apple.com/forums/thread/688697

My customers who installed ios 15.0(iPhone 11) & 15.0.1(iPhone 12 pro) have the same problems with UserDefaults which had been wiped out a few hours later after the launch of the app. 

And of course, it's after "didFinishLaunching" and I try to retrieve it several times at different timing. 

I don't know if it is related to the other issue. https://developer.apple.com/forums/thread/688697

We're experiencing the same issue with UserDefaults. Only one out of three of our apps is experiencing this issue. The solution introduced by @nickfromnelson did not solve the problem. Our temporary solution was to replace UserDefaults with our implementation for the time being.

Have the same issue. But I found strange app behavior on iOS 15.0. When the iPhone screen is locked and the app was closed(terminated), in 10 minutes iOS 15 opens it automatically in the background mode (didFinishLaunchingWithOptions, UIApplication.shared.applicationState == .background, the screen is still locked), keychain returns null, the app starts sending requests to my server (see requests in the Charles proxy).

Then when I unlock the screen, I don't see that my app is in the background mode, but when I tap on the app icon, the app opens, didFinishLaunchingWithOptions is not called.

Tested on iOS 15.1. Print logs into UserDefaults. Maybe somebody knows how to disable this background feature?   

This answer solved this issue for us.

iOS 15 beta wipes out app data
 
 
Q