【问题标题】:What am I missing to get my iOS app entitled for iCloud?为了让我的 iOS 应用程序有权使用 iCloud,我缺少什么?
【发布时间】:2015-11-16 17:34:19
【问题描述】:

我正在尝试将 iCloud 功能添加到现有应用程序。我正在使用 UIManagedDocument 来引用核心数据。我对此进行了大量研究,但我无法弄清楚我做错了什么。

我已经尝试在我的 Macbook 和 Mac Mini 上使用它。我尝试关闭 iCloud 功能,退出 Xcode,然后重新打开 Xcode 并重新打开 iCloud 功能。没有运气。

我认为它没有权利的原因是因为:

  1. 我没有看到 Cloud Debug Gauge。
  2. 当我在模拟器中触发 iCloud 同步时,我收到一条错误消息:

操作无法完成。 (BRCloudDocsErrorDomain 错误 2 - 已注销 - 未配置 iCloud Drive)

  1. 以下解析为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"
                                         };

在上面的代码之后,它执行openWithCompletionHandlersaveToURL:url forSaveOperation:UIDocumentSaveForCreating。我还注册了收到有关NSPersistentStoreCoordinatorStoresDidChangeNotification 的通知,这正在发生。

【问题讨论】:

  • 你在模拟器上登录了 iCloud 吗?您是在设备上运行应用程序还是只在模拟器上运行该应用程序?
  • 在我的 iPad 上运行确实会调出 iCloud Debug Gauge。感谢那。我确保我的 Mac 已登录 iCloud,但没有登录模拟器本身。我登录了模拟器的设置,因此它链接到了我的 iCloud。 ubiquityIdentityToken 不再为零,但在模拟器上我仍然看不到 iCloud 调试仪表。
  • 即使我的模拟器没有显示 iCloud Debug Gauge,但模拟器的 iCloud 正在工作,因为我的 iPad 正在模拟器上进行更新。感谢您的帮助!

标签: ios objective-c icloud uimanageddocument


【解决方案1】:

iCloud Debug Gauge 可能不适用于在模拟器中运行的应用程序,因为它没有完整的功能。这是从 2014 年开始的,所以事情可能已经改变了。

但是,模拟器不完全支持 iCloud Core Data。在跨设备和模拟器进行测试时,模拟器上的 iCloud Core Data 似乎只上传更改,而不会将它们拉回。与需要单独的测试设备相比,这仍然是一个很大的改进,并且非常方便,但 iOS 模拟器上的 iCloud Core Data 支持肯定还没有完全成熟。

http://www.objc.io/issues/10-syncing-data/icloud-core-data/

我在官方文档中唯一能找到的内容是:

在实际设备上测试支持 iCloud 的 iOS 应用程序尤为重要。 iOS Simulator 无法准确模拟真实条件下 iCloud 的使用。

https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/UsingCoreDataWithiCloudPG/UsingSQLiteStoragewithiCloud/UsingSQLiteStoragewithiCloud.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    相关资源
    最近更新 更多