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

  • 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

Add a Comment

Replies

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.

  • I can reproduce this consistently now:

    Save auth token to keychain...Kill app entirely & put device to sleep...Wait at least 20 minutes...Restart the app & the auth token has been wiped...

    I'm on an iPad (6th Gen), iPadOS 15 beta.

  • See my above comments above. Above approach might fix your issue.

  • Thanks for reproducing steps! On iOS 15 I reproduce it in same way but want to emphasize that for me it works after 25-30 minutes in DND sleep mode (focus mode in iOS 15)

Add a Comment

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 also observed the same and it fixed the issue after I moved the API call to didFinishLaunching

Add a Comment

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

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

  • I have two apps that use the keychain. One is working fine while the other stops after few hours. I've noticed that if I remove that app from the task manager, I get a very limited access to the keychain and the app works partially. It still happens in iOS 15.1 beta. It worked fine in previous iOS versions

Add a Comment

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?   

  • Update: Found root cause. In my case, the background push notification opens the closed app in  .background mode, sometimes keychain in the didFinishLaunchingWithOptions method returns nill instead of my tokens.

Add a Comment

This answer solved this issue for us.