为了让我的iOS应用程序有权使用iCloud,我缺少什么?

时间:2015-08-23 03:38:03

标签: ios objective-c icloud uimanageddocument

我正在尝试将iCloud功能添加到现有应用中。我使用UIManagedDocument来引用Core Data。我已经对此进行了大量研究,但我无法弄清楚我做错了什么。

我已尝试将其用于Macbook和Mac Mini上。我尝试关闭iCloud功能,退出Xcode,然后重新打开Xcode并重新打开iCloud功能。没有运气。

我之所以认为它的名字是因为:

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

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

    1. 以下解析为nil [[NSFileManager defaultManager] ubiquityIdentityToken]
    2. 设置屏幕截图

      设置了iCloud功能。

      enter image description here

      App ID已启用iCloud。

      enter image description here

      我的配置文件说明了它为iCloud设置的问题。当我切换到Mac Mini时,我也撤销并重新授权。

      enter image description here

      我看到一篇关于Xcode 6测试版的帖子没有正确设置权限,但是接近我可以说这没关系。我确实尝试将Ubiquity容器标识符更改为$(TeamIdentifierPrefix)$(CFBundleIdentifier),但它似乎没有什么区别。

      enter image description here

      代码

      问题可能与我的代码有关?下面唯一的新部分是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的通知,并且发生了这种情况。

1 个答案:

答案 0 :(得分: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模拟器无法在真实条件下准确模拟iCloud的使用。

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

相关问题