【发布时间】:2015-11-16 17:34:19
【问题描述】:
我正在尝试将 iCloud 功能添加到现有应用程序。我正在使用 UIManagedDocument 来引用核心数据。我对此进行了大量研究,但我无法弄清楚我做错了什么。
我已经尝试在我的 Macbook 和 Mac Mini 上使用它。我尝试关闭 iCloud 功能,退出 Xcode,然后重新打开 Xcode 并重新打开 iCloud 功能。没有运气。
我认为它没有权利的原因是因为:
- 我没有看到 Cloud Debug Gauge。
- 当我在模拟器中触发 iCloud 同步时,我收到一条错误消息:
操作无法完成。 (BRCloudDocsErrorDomain 错误 2 - 已注销 - 未配置 iCloud Drive)
- 以下解析为
nil。[[NSFileManager defaultManager] ubiquityIdentityToken]
设置截图
iCloud 功能已设置。
App ID 开启了 iCloud。
我的配置文件说它是为 iCloud 设置的。当我切换到我的 Mac Mini 时,我也撤销并重新授权。
我看到一篇关于 Xcode 6 beta 没有正确设置权利的帖子,但据我所知,这没关系。我确实尝试将 Ubiquity Container Identifier 更改为 $(TeamIdentifierPrefix)$(CFBundleIdentifier),但似乎没有什么不同。
代码
也许问题出在我的代码上?下面唯一的新部分是NSPersistentStoreUbiquitousContentNameKey: @"iCloudStore"。
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] firstObject];
url = [url URLByAppendingPathComponent:DATABASE_DOCUMENT_NAME];
self.document = [[UIManagedDocument alloc] initWithFileURL:url];
// To cause light-weight model version migration to occur.
self.document.persistentStoreOptions = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES,
NSPersistentStoreUbiquitousContentNameKey: @"iCloudStore"
};
在上面的代码之后,它执行openWithCompletionHandler 或saveToURL:url forSaveOperation:UIDocumentSaveForCreating。我还注册了收到有关NSPersistentStoreCoordinatorStoresDidChangeNotification 的通知,这正在发生。
【问题讨论】:
-
你在模拟器上登录了 iCloud 吗?您是在设备上运行应用程序还是只在模拟器上运行该应用程序?
-
在我的 iPad 上运行确实会调出 iCloud Debug Gauge。感谢那。我确保我的 Mac 已登录 iCloud,但没有登录模拟器本身。我登录了模拟器的设置,因此它链接到了我的 iCloud。 ubiquityIdentityToken 不再为零,但在模拟器上我仍然看不到 iCloud 调试仪表。
-
即使我的模拟器没有显示 iCloud Debug Gauge,但模拟器的 iCloud 正在工作,因为我的 iPad 正在模拟器上进行更新。感谢您的帮助!
标签: ios objective-c icloud uimanageddocument