iOS核心数据+ iCloud错误,用于addPersistentStoreWithType:您无权将文件“store”保存在文件夹中

我从头开始创建了一个Core Data项目,我唯一的变化就是持久协调器添加了一个商店,我提供了一个NSPersistentStoreUbiquitousContentNameKey选项:

coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: [NSPersistentStoreUbiquitousContentNameKey : "coreDataiCloudTestStore"]) 

我正在启动时插入并保存一个新的托管对象。

在启动时,没有登录iCloud帐户,没有问题。 当应用程序运行时,我正在登录iCloud并返回应用程序。 我收到此错误:您无权将文件“store”保存在文件夹中,不允许操作:

CoreData:错误:-addPersistentStoreWithType:SQLite配置:PF_DEFAULT_CONFIGURATION_NAME URL:file:///var/mobile/Containers/Data/Application/9032B2BC-BE8B-42C9-A9CC-EF3E01AA6F2B/Documents/SingleViewCoreData.sqlite options:{NSPersistentStoreUbiquitousContentNameKey = coreDataiCloudTestStore; PFUbiquitySetupSynchronousSideLoadKey = 1; }

…返回错误错误Domain = NSCocoaErrorDomain Code = 513“您无权将文件”store“保存在文件夹 ”380E290C-97F9-4DC3-9B3C-43322FCA455D“中。” 的UserInfo = {NSFilePath =的/ var /移动/容器/数据/应用/ 9032B2BC-BE8B-42C9-A9CC-EF3E01AA6F2B /文档/ CoreDataUbiquitySupport /移动〜C5A2ECE3-1AB9-45FA-9C15-037DCCA054DE / coreDataiCloudTestStore / 380E290C-97F9-4DC3-使用userInfo字典{NSFilePath =“/ var / mobile / Containers / Data / Application / 9032B2BC-BE8B-42C9-A9CC- EF3E01AA6F2B /文档/ CoreDataUbiquitySupport /移动〜C5A2ECE3-1AB9-45FA-9C15-037DCCA054DE / coreDataiCloudTestStore / 380E290C-97F9-4DC3-9B3C-43322FCA455D /存储“; NSUnderlyingError =“Error Domain = NSPOSIXErrorDomain Code = 1 \”操作不被允许\“”; }

PFUbiquitySwitchboardEntry containerIdentifierChanged :: CoreData:Ubiquity: 使用选项 {{NSPersistentStoreUbiquitousContentNameKey = coreDataiCloudTestStore;} 更改帐户后加载新的临时协调员时出错。 和URL文件:///var/mobile/Containers/Data/Application/9032B2BC-BE8B-42C9-A9CC-EF3E01AA6F2B/Documents/SingleViewCoreData.sqlite and error = Error Domain = NSCocoaErrorDomain Code = 513“ 你还没有允许将文件“store”保存在文件夹 “380E290C-97F9-4DC3-9B3C-43322FCA455D”中。“ 的UserInfo = {NSFilePath =的/ var /移动/容器/数据/应用/ 9032B2BC-BE8B-42C9-A9CC-EF3E01AA6F2B /文档/ CoreDataUbiquitySupport /移动〜C5A2ECE3-1AB9-45FA-9C15-037DCCA054DE / coreDataiCloudTestStore / 380E290C-97F9-4DC3- 9B3C-43322FCA455D / store,NSUnderlyingError = 0x1453f430 {错误域= NSPOSIXErrorDomain代码= 1“不允许操作”}}

为什么会这样?

从iCloud重建

要删除本地数据并使用iCloud中的现有记录重新开始,请在将持有iCloud的持久存储添加到持久性存储协调器时,将NSPersistentStoreRebuildFromUbiquitousContentOption选项与值@YES一起传递。 包括您通常包含的任何iCloud选项。