Xcode Version 11.5 CloudKit not working on simulator

Viewed 485

before the last update, I was able to manage data with CloudKit on simulator, with the last updating, it's not working, also if I add a file in iCloud Drive, in simulator the folder is not updated.

in my func, I receive couldNotComplete status:

defaultContainer.requestApplicationPermission(.userDiscoverability, completionHandler: {status, error in
            switch status {
            case .denied:
                DispatchQueue.main.async {//necessario perchè lo fa in background e potrebbe crashare senza questo
                    completionHandler(status)
                    self.showSettingsAlert()
                }
            case .initialState:
                DispatchQueue.main.async {
                    completionHandler(status)
                    self.showSettingsAlert()
                }
            case .couldNotComplete:
                DispatchQueue.main.async {
                    completionHandler(status)
                    self.showSettingsAlert()
                }
                print("@couldNotComplete requestApplicationPermission (func getUserPermission) - probabilmente non ha un account icloud")                
            case .granted:
                completionHandler(status)
            @unknown default:
                print("@unknown requestApplicationPermission (func getUserPermission)")
            }
        })

but the problem is in the token:

Optional("Couldn\'t get an authentication token")

Do you have the same problem?

2 Answers

Sorry that I can't help with an answer, but I can say that it isn't just you; this started happening to me too. Some things I know:

  • Everything works initially, and then at some point I'm asked to re-enter my iCloud password ("Apple ID Verification").

  • The simulator accepts the password, but past that point CloudKit (and more) stop working.

  • Here's the error CloudKit returns: Optional(<CKError 0x600002b08b10: "Not Authenticated" (9/2011); "Couldn't get an authentication token">)

  • I tried using "Features | Trigger iCloud Sync" to see if that would kick iCloud into working, but it didn't.

  • Signing out on the iPhone simulators never seems to end; so far I've always had to use "Erase All Content and Settings". After that things work again, but not for long.

  • Signing out on an iPad simulator worked once. After signing back in, everything started working again. Well, so far. :-)

  • I'm using a test account. I wondered if Apple thought it was a spam account, so I logged into https://appleid.apple.com with it and turned on two-factor authentication, etc. None of that made a difference.

  • Here are some things I'm planning to try, roughly in order:

    • new simulator using iOS 13.4 (I'm currently using 13.5)
    • new test account
    • Xcode 12 beta

===

So far I've tried:

  • New simulator using iOS 13.4
  • Xcode 12 beta
  • Rebooting my Mac

Ultimately, none of those things have worked; once I start getting the "Couldn't get an authentication token" error--and I typically get it within 24 hours--the only thing that makes the simulator work again is erasing it.

One thing I'm not sure of is whether, once a simulator is in that state, anything can recover it. For example, when I first launched the Xcode 12 beta, and first ran the simulator, it immediately asked for the password. Did the beta start from an already corrupted simulator? More to the point, would Xcode 12 beta corrupt a simulator on its own, or was it just picking up on an error that was actually created by Xcode 11.5? I don't know.

I'll try a few more things...

===

Creating a new test account didn't work, but I may have found something that does: resetting the keychain. Here's how to do it from the command-line:

xcrun simctl keychain reset <device>

After running that command the simulator once again asks for the iCloud password, but the password now produces the expected result: iCloud starts working again.

(If your app was running when you reset the keychain you'll probably have to restart it, or somehow otherwise give it a kick so that it notices the change.)

Simone Pistecchia's comment helped me the most. In the simulator menus select Device > Erase All Content and Settings for each simulator that is having the problem. Then resign into iCloud.

Related