I am trying to export the sqlite that I've created for core data to store the records locally to the app that I am developing.
I have managed to export the sqlite file via e-mail as attachment, but when I extracted the sqlite file the data is not complete, newly added records aren't shown.
Here's my code for export through e-mail,
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];
}