6

I'm using NSPersistentCloudKitContainer on iOS15 beta 4 to sync core data across devices. When launching on device, logged into iCloud, I receive the following error in the logs:

<NSCloudKitMirroringResult: 0x28167ae60> success: 0 madeChanges: 0 error: <CKError 0x2818a94d0: "Account Temporarily Unavailable" (1028/2011); "Account temporarily unavailable due to bad or missing auth token">

I have the following code:

init(inMemory: Bool = false) {
        container = NSPersistentCloudKitContainer(name: "AppName")
        if inMemory {
            let storeDescription = NSPersistentStoreDescription(url: URL(fileURLWithPath: "/dev/null"))
            container.persistentStoreDescriptions = [storeDescription]
        } else {
            let storeURL = URL.storeURL(for: "my.app.group", databaseName: "AppName")
            let storeDescription = NSPersistentStoreDescription(url: storeURL)
            storeDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.my.app")
            container.persistentStoreDescriptions = [storeDescription]
        }
        
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
    }
ryannn
  • 1,329
  • 1
  • 9
  • 21

2 Answers2

4

This appears to be a bug introduced on beta 4 - https://developer.apple.com/forums/thread/685857

ryannn
  • 1,329
  • 1
  • 9
  • 21
1

As @ryannnn pointed out it seems to be a bug that seems to be fixed in beta 5. I had a similar problem specifically with the public CK database. I'll edit this, if I can confirm that b5 fixed it for me...

EDIT: it did fix the Account Temporarily Unavailable issue. However, the iCloud sync still only happens while in the first session after app install. When running it again, after it's installed I still get <CKError 0x281fe43f0: "Server Rejected Request" (15/2027); server message = "Custom zones are not allowed in public DB"; op = *****; uuid = ***-***-***>.

thisIsTheFoxe
  • 1,584
  • 1
  • 9
  • 30
  • Could you solve this problem ? I got the same problem. iCloud sync does work at first but later the same error message appears. – TBH Nov 10 '21 at 14:50
  • Sorry, I gave up on the feature I had planned and pivoted .-. I'll let you know if I ever come back to it.. – thisIsTheFoxe Jan 23 '22 at 17:58