我在 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)")
}
})
}