コア データ用に作成した sqlite をエクスポートして、開発中のアプリにレコードをローカルに保存しようとしています。
sqlite ファイルを電子メールで添付ファイルとしてエクスポートできましたが、sqlite ファイルを抽出すると、データが完全ではなく、新しく追加されたレコードが表示されません。
電子メールでエクスポートするための私のコードは次のとおりです。
NSString *filePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"CoreDataModel.sqlite"];
NSError *error = nil;
NSData *fileData = [[NSData alloc] initWithContentsOfFile:filePath options:0UL error:&error];
if (error != nil) {
NSLog(@"Failed to read the file: %@", [error localizedDescription]);
} else {
if (fileData == nil) {
NSLog(@"File data is nil");
}
}
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
if (mailView != nil) {
mailView.mailComposeDelegate = self;
[mailView setSubject:@"Records"];
[mailView addAttachmentData:fileData
mimeType:@"application/x-sqlite3"
fileName:@"CoreDataModel.sqlite"];
[mailView setMessageBody:@"Database attached"
isHTML:NO];
[self presentViewController:mailView animated:YES completion: NULL];
}