iOS15 B4 NSPersistentCloudKitContainer“帐户暂时不可用”错误

rya*_*nnn 6 ios swift cloudkit nspersistentcloudkitcontainer

我在 iOS15 beta 4 上使用 NSPersistentCloudKitContainer 来跨设备同步核心数据。在设备上启动并登录 iCloud 时,我在日志中收到以下错误:

<NSCloudKitMirroringResult:0x28167ae60>成功:0 madeChanges:0错误:<CKError 0x2818a94d0:“帐户暂时不可用”(1028/2011);“由于身份验证令牌错误或丢失,帐户暂时不可用”>

我有以下代码:

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)")
            }
        })
    }
Run Code Online (Sandbox Code Playgroud)

rya*_*nnn 4

这似乎是 beta 4 中引入的错误 - https://developer.apple.com/forums/thread/685857