我正在通过电子邮件发送 SQLite(Coredata sqlite文件)文件,但在收到的邮件的所有表中都发现空数据。
我正在使用以下代码:
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:subject];
[mc setMessageBody:body isHTML:FALSE];
if (attachmentData) {
[mc addAttachmentData:attachmentData mimeType:fileMimeType fileName:fileName];
}
if (!recipients || recipients.count == 0) {
recipients = @[];
}
[mc setToRecipients:recipients];
[presentedViewController presentViewController:mc animated:YES completion:nil];
在这里,fileMimeType =“ application / x-sqlite3”和文件名:xyz.sqlite
在此处找到相同的question,但没有解决方案。知道怎么做吗?
答案 0 :(得分:1)
正如我在评论中指出的那样,iOS默认使用SQLite的WAL模式,因此您需要将WAL文件作为附件包含。
答案 1 :(得分:0)
通过发送一个简单的示例数据库,此测试代码对我来说似乎很好:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self sendSampleMailWithDbAttached];
}
- (void)sendSampleMailWithDbAttached {
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:@"Message Subject"];
[mc setMessageBody:@"Message Body" isHTML:NO];
NSString *sqliteFilePath = [self createTestDb];
NSData *attachmentData = [NSData dataWithContentsOfFile:sqliteFilePath];
if (attachmentData) {
[mc addAttachmentData:attachmentData mimeType:@"application/x-sqlite3" fileName:@"xyz.sqlite"];
}
[mc setToRecipients:@[@"fake@email.com"]];
[self presentViewController:mc animated:YES completion:nil];
}
- (NSString *)createTestDb {
NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
stringByAppendingPathComponent: @"xyz.sqlite"];
sqlite3 *db;
if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {
NSString *query = @"CREATE TABLE IF NOT EXISTS test(abc TEXT, def TEXT);";
if (sqlite3_exec(db, [query UTF8String], NULL, NULL, NULL) == SQLITE_OK) {
query = @"INSERT INTO test(abc, def) VALUES('ABC', '123');";
}
sqlite3_close(db);
}
return databasePath;
}