【发布时间】:2014-11-27 16:29:25
【问题描述】:
我想备份和检索核心数据中的 sqlite3 数据库。这是为了快速保存和恢复保存在应用程序中的用户数据。计划是通过电子邮件发送数据库,然后在接收设备上打开它,所有以前的数据都会神奇地出现,一切都很好。
我已经阅读了很多关于这个主题的帖子和文档,但是将它们放在一起是我可以提出一些建议的地方。
到目前为止我做了什么:
我已设法使用以下方式向sqlite3database 发送电子邮件
NSString *filePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"db.sqlite"];
NSError *error = nil;
NSData *fileData = [[NSData alloc] initWithContentsOfFile:filePath options:0UL error:&error];
if (error != nil) {
DebugLog(@"Failed to read the file: %@", [error localizedDescription]);
} else {
if (fileData == nil) {
DebugLog(@"File data is nil");
}
}
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
if (mailView != nil) {
mailView.mailComposeDelegate = self;
[mailView setSubject:@"back up database"];
[mailView addAttachmentData:fileData
mimeType:@"application/octet-stream"
fileName:@"db.sqlite3"];
[mailView setMessageBody:@"Database attached"
isHTML:NO];
[self presentViewController:mailView animated:YES completion: NULL];
}
进一步的研究让我相信我必须将其他期刊文件附加到此? iOS: How can I create a backup copy of my core data base? And how to export/import that copy?
我已将这些文档记录为db.sqlite db.sqlite-shm db.sqlite-wal
我的问题是
1. 我是否将所有这些db.sqlite db.sqlite-shm db.sqlite-wal 作为电子邮件的附件发送?
2. 接收这些文件并将它们复制到应用程序中的程序是什么。
仅打开附件不起作用,因为它只能由某些应用程序读取。然后,我在 info.plist 中创建了 Document 类型,我的应用程序作为接收文档的应用程序出现在操作表中,但应用程序崩溃并出现错误 incomprehensible archive
总之,我该如何保存和恢复我的核心数据
【问题讨论】:
标签: ios objective-c core-data sqlite