备份恢复SQLite核心数据iphone
我正在开发一个项目,在该项目中创建应用程序 sqllite 文件的实例并进行设置,以便用户可以将备份文件通过电子邮件发送到他/她自己的电子邮件。我已经在 iStudiezPro 上看到了这一点,它的效果非常神奇。
我可以收到电子邮件来打开应用程序文件并进行恢复,问题是持久性存储要更新应用程序必须重新加载。 当回到应用程序时,我这样做:
[persistentStoreCoordinator release];
persistentStoreCoordinator = nil;
[managedObjectContext release];
managedObjectContext = nil;
[primaryUserManagedObject release];
primaryUserManagedObject = nil;
[self managedObjectContext];
我只需要找到一种方法让应用程序在应用程序运行时重建核心数据堆栈。任何帮助将不胜感激。
I'm working on a project where I create a instance of my app sqllite file and set it up so the user can email the backup file to his/her own email. I've seen this done on iStudiezPro and it works magically.
I can get the email to open up the app file and restore, the problem is that for the persistence store to update the app would have to reload.
When coming back to the app I do this:
[persistentStoreCoordinator release];
persistentStoreCoordinator = nil;
[managedObjectContext release];
managedObjectContext = nil;
[primaryUserManagedObject release];
primaryUserManagedObject = nil;
[self managedObjectContext];
I just need to find a way for the app to rebuild the core data stack while the app is running. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的解决方案是仅保存上下文,然后使用标准 fileManager 方法将存储文件复制到文档文件夹。如果您确保没有正在进行的核心数据操作,我认为您不会遇到任何损坏问题。
如果您需要额外的保护,请在复制之前释放并清空 ManagedObject 上下文,然后释放持久存储协调器。复制完成后,重建堆栈。没有理由重新启动应用程序本身。您可能必须创建一个专用对象来管理核心数据堆栈,以便可以打开和关闭它。
The easiest solution would be to just save the context and then copy the store file to the documents folder using standard fileManager methods. If you make sure that there are no ongoing Core Data operations, I don't think you will have any problems with corruption.
If you want extra protection, before you copy, release and nil the managedObject context and then the persistent store coordinator. When the copy is done, rebuild the stack. There is no reason to restart the app itself. You probably will have to create a dedicated object to manage the Core Data stack so that it can be turned on and off.
我上传了一个示例应用程序,它以多种不同的方式提供备份和恢复功能,包括本地备份、将备份复制到 iCloud 或从 iCloud 复制备份、电子邮件备份、从电子邮件导入以及通过 iTunes 复制文件。请参阅下面的链接,了解演示这些功能的视频,您可以从该网站下载示例应用程序。
http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-集成/示例应用程序解释/备份文件/
I have uploaded a sample app that provides backup and restore capabilities a number of different ways, including local backups, copy backups to and from iCloud, email backups, import from email, and file copy via iTunes. See link below for video demonstrating these capabilities and you can download the sample apps from the site.
http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/sample-apps-explanations/backup-files/