Core Data和iCloud添加预填充的sqlite文件 [英] Core Data and iCloud adding Pre-Populated sqlite file

查看:169
本文介绍了Core Data和iCloud添加预填充的sqlite文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用Core Data和iCloud在多个iPad之间同步数据的应用程序。这一切工作正常,我可以添加数据到每个iPad,它将在它们之间同步。

I'm working on an app that uses Core Data and iCloud to sync data between multiple iPads. This is all working fine and I can add data to each iPad and it will sync between them all.

我有一个Core Data sqlite文件,该文件预填充了一系列国家/地区,我想在首次运行应用程序时将其复制到文档区域。我有这个工作,但已经改变了我的persistentStoreCoordinator实现来测试iCloud支持或一些其他小的变化。

I have a Core Data sqlite file that is pre-populated with a list of countries and I want to copy this to the documents area on first run of the app. I had this working but have changed my persistentStoreCoordinator implementation to test for iCloud support or not and a couple of other small changes.

然而,现在当我检查,看看sqlite文件存在并复制预填充的sqlite文件,如果它不会在

However now when I check to see if the sqlite file exists and copy the pre-populated sqlite file if it doesn't I get the following error at

[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:iCloudData] options:options error:&persistentStoreError];




NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error :: CoreData: Ubiquity:设置无处不在集成时出错:Error Domain = NSCocoaErrorDomain Code = 134316无处不在的容器似乎不匹配此持久存储,这可能是由切换到不同的iCloud帐户或登出iCloud。应该用只读属性重新打开商店,或者从iCloud永久删除。 UserInfo = 0x1cb590 {storeUUID = 31381598-EAFA-4550-9B96-F501800974D5,containerUUID = E3A8DC7D-41FD-405A-8D8A-C06C8B467CA2,NSLocalizedDescription =无处不在容器似乎不匹配此持久存储,这可能是由切换到不同的iCloud帐户,或完全注销iCloud。应该用只读属性重新打开商店,或永久从iCloud同步中删除商店。}

NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:: CoreData: Ubiquity: An error occured while setting up the ubiquity integration: Error Domain=NSCocoaErrorDomain Code=134316 "The ubiquity container does not appear to match this persistent store, it is possible this is caused by switching to a different iCloud account, or logging out of iCloud entirely. The store should be re-opened with read-only attributes or removed from iCloud syncing permanently." UserInfo=0x1cb590 {storeUUID=31381598-EAFA-4550-9B96-F501800974D5, containerUUID=E3A8DC7D-41FD-405A-8D8A-C06C8B467CA2, NSLocalizedDescription=The ubiquity container does not appear to match this persistent store, it is possible this is caused by switching to a different iCloud account, or logging out of iCloud entirely. The store should be re-opened with read-only attributes or removed from iCloud syncing permanently.}

在iCloud到不同的Core Data sqlite文件或事务日志文件?

Is this because there are still references in iCloud to a different Core Data sqlite file or transaction log files? If so how would I remove them?

推荐答案

您不应该将预先创建的Core Data存储复制到无处不在的容器。执行此操作的旧方法是在Simulator /设备/计算机上创建一个SQLite文件,并在首次运行时将其复制到它的位置。如果你使用iCloud,你不能再这样做了。 iCloud通过每个设备接收更改列表作为事务日志,然后它应用于它自己的SQLite存储。它需要知道发生了什么变化,并且一个.sumpite文件在一个块中不会告诉它。

You're not supposed to copy a pre-created Core Data store to the ubiquity container. The old way to do this was to create an SQLite file on the Simulator/device/computer and copy it into it's place on first run. If you use iCloud, you can't do this any more. iCloud works by each device receiving a list of changes as "transaction logs", which it then applies to it's own SQLite store. It needs to know what's changed, and getting a .sqlite file in one lump won't tell it that.

iCloud的方法是:

The iCloud way to do this is either:


  • 从代码内部创建初始数据(例如 insertStartData:方法)。你可以从plist或任何你喜欢的添加它。

  • 使用 NSPersistentStoreCoordinator

  • Create the initial data from inside your code (e.g. an insertStartData: method). You could add it from a plist, or whatever you like. You'll have to check that the data isn't already there first.
  • Use NSPersistentStoreCoordinator's migratePersistentStore:toURL:options:withType:error to copy your initial store across.

Here's the docs:


您不应该使用预先打包的数据库文件种子初始内容。相反,您应该在代码中创建默认项,或者使用NSPersistentStoreCoordinator的migratePersistentStore:toURL:options:withType:error:方法将预先打包的数据库迁移到所需位置。

You should not seed initial content with a prepackaged database file. Instead, you should create the default items in code, or use NSPersistentStoreCoordinator's migratePersistentStore:toURL:options:withType:error: method to migrate a prepackaged database to the required location.

这篇关于Core Data和iCloud添加预填充的sqlite文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆