iCloud同步失败,出现"CoreData:Ubiquity:Invalid选项:NSPersistentStoreUbiquitousContentNameKey的值不应包含句点"

Sou*_*ker 9 core-data ios icloud magicalrecord

CoreData:Ubiquity:无效选项:NSPersistentStoreUbiquitousContentNameKey的值不应包含句点:com.YashwantChauhan.Outis

-PFUbiquitySwitchboardEntryMetadata setUseLocalStorage :: CoreData:Ubiquity:mobile~20BF44C9-C39F-48DC-A8A1-B45FC82C7E20:com.YashwantChauhan.Outis

我遇到与iCloud同步的问题.上面这两个错误都被抛到了我的身上.我不知道是什么问题,我设置了Entitlements文件,并将Ubiquity容器设置为com.YashwantChauhan.Outis.

我使用MagicalRecord的方法启动CoreData堆栈:

[MagicalRecord setupCoreDataStackWithiCloudContainer:@"N6TU2CB323.com.YashwantChauhan.Outis" localStoreNamed:@"Model.sqlite"];
Run Code Online (Sandbox Code Playgroud)

但这甚至不应该重要,因为MagicalRecord只是简化了CoreData方法.

非常感谢.

好的更新:

- [NSFileManager URLForUbiquityContainerIdentifier:]:获取普遍容器URL时出错:Error Domain = LibrarianErrorDomain Code = 11"操作无法完成.(LibrarianErrorDomain错误11 - 客户端的com.apple不允许请求的容器标识符.developer.ubiquity-container-identifiers entitlement.)"UserInfo = 0x15e0d8a0 {NSDescription =客户端的com.apple.developer.ubiquity-container-identifiers权利不允许请求的容器标识符.}

这是我收到的最新错误消息,我意识到这与问题的初始错误不同,但事实证明旧消息是某种奇怪的错误.我通过删除Ubiquity Container标识符中的句点来尝试@Rauru Ferro的解决方案.我知道这不会起作用,因为标识符的要求是包含句点,但是当我将句点放回时,它会将上面的错误消息吐出来.这比使用句点更有意义.我们都知道我们这样做.

我还发现了这个方便的代码片段,可以通过获取它来实际检查我的Ubiquity Container标识符.有用的代码片段可以快速检查您是否有任何问题.

NSString *containerId = @"com.YashwantChauhan.Outis";
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *iCloudURL = [fileManager URLForUbiquityContainerIdentifier:containerId];
NSLog(@"%@", [iCloudURL absoluteString]);
Run Code Online (Sandbox Code Playgroud)

另一个更新:从它的外观来看,这个愚蠢NSPersistentStoreUbiquitousContentNameKey should not contain periods是一团糟.如果NSPersistentStoreUbiquitousContentNameKey创建像某种文件夹(Tutorial),那么要求是没有.名称的前面,.com.YashwantChauhan.Outis但事实并非如此.我开始疯了!Entitlements文件没有问题,并且在MagicalRecord中没有提取iCloud容器ID.我开始认为这是在Xcode 5中设置iCloud的内部问题,但我当然不知道.有了这个说法,我可能会对一些微不足道的东西或其他会让其他人头痛的事情失去理智.

任何人都可以发布他们的Entitlements文件,以便我可以验证实际工作版本的样子.当然是编辑的.谢谢!

Dav*_*son 5

请参阅 https://forums.pragprog.com/forums/252/topics/12315

引用回复:

这最近改变了(小牛队).幸运的是,由于您刚刚添加iCloud,因此影响很小.

您需要更改以下代码行:

[options setValue:[[NSBundle mainBundle] bundleIdentifier] forKey:NSPersistentStoreUbiquitousContentNameKey]; 别的.那是什么东西?我会推荐一些描述你的应用程序的东西.我最近一直在使用类名结构.因此,我可能会将其更改为您的应用程序的名称或简称为"DataStorage".

该名称对于您的应用程序是唯一的,因此只要您了解它,实际值并不重要.

所以我在下面改了我的代码......

        options = [NSDictionary dictionaryWithObjectsAndKeys:
                   [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,     // Key to automatically attempt to migrate versioned stores
               [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,           // Key to attempt to create the mapping model automatically
               @"TrafficCamNZ_DataStore", NSPersistentStoreUbiquitousContentNameKey,                // Option to specify that a persistent store has a given name in ubiquity.
               cloudURL, NSPersistentStoreUbiquitousContentURLKey,                              // Option to specify the log path to use for ubiquitous content logs.
               nil];
Run Code Online (Sandbox Code Playgroud)

请参阅之前有TrafficCamNZ.DataStore的TrafficCamNZ_DataStore行

  • 大卫