mardi 24 février 2015

Export SQLite file in document directory via email

I am trying to export a SQLite file via email located in the document directory when a user taps on the exportAllData button. Using the code below, I was able to open up the mail app and attach a file. However when I send it, the file does not get sent with the email.



- (IBAction)exportAllDataButtonPressed:(id)sender
{
MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init];
composer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail])
{
[composer setToRecipients:[NSArray arrayWithObjects:@"test@test.com",nil]];
[composer setSubject:@"SQLite File"];
[composer setMessageBody:@"This is your SQLite file" isHTML:NO];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);

NSString *documentDirectory = [paths objectAtIndex:0];
NSString *path = [documentDirectory stringByAppendingPathComponent:@"mooddb.sql"];
NSData *myData = [NSData dataWithContentsOfFile:path];

[composer addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:path];
[self presentViewController:composer animated:YES completion:nil];
}
}

Aucun commentaire:

Enregistrer un commentaire