Attaching sqlite to xcode mail

I'm crazy about this code, it should work, but when I receive mail there is no file attached, here is my code:

-(IBAction)mandar:(id)sender { MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init]; [composer setMailComposeDelegate:self]; if ([MFMailComposeViewController canSendMail]) { [composer setToRecipients:[NSArray arrayWithObjects:@" tuperroensalsa@hotmail.com ",nil]]; [composer setSubject:@"Base de datos"]; [composer setMessageBody:@"Mensage" isHTML:NO]; [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentPath = [searchPaths objectAtIndex:0]; NSString *path = [[NSString alloc] initWithFormat:@"%@/capturas.sqlite",documentPath]; NSString *Newpath = [[NSString alloc] initWithFormat:@"%@/newData.sqlite",documentPath]; [[NSFileManager defaultManager] copyItemAtPath:path toPath:Newpath error:nil]; NSData *data = [NSData dataWithContentsOfFile:Newpath]; [composer addAttachmentData:data mimeType:@"application/x-sqlite3" fileName:@"capturas.sqlite"]; [self presentModalViewController:composer animated:YES]; } else { UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:@"No se a podido mandar el mensage" delegate:self cancelButtonTitle:@"dismis" otherButtonTitles:nil, nil]; [alert show]; } } 

The path is fine, and there is data in the database, I also see the file when I compose mail, but nothing comes to my mail. I think the problem is here.

 [composer addAttachmentData:data mimeType:@"application/x-sqlite3" fileName:@"capturas.sqlite"]; 

but donโ€™t know why it doesnโ€™t work, thanks for reference

+4
source share
1 answer

I already updated the answer: Error sending database from xCode , but it seems you did not check it, anyway:

 -(IBAction)mandar:(id)sender { MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init]; [composer setMailComposeDelegate:self]; if ([MFMailComposeViewController canSendMail]) { [composer setToRecipients:[NSArray arrayWithObjects:@"EMAIL Address here",nil]]; [composer setSubject:@"Base de datos"]; [composer setMessageBody:@"Mensage" isHTML:YES]; [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 

Commented this out from your code:

 // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *documentsDirectory = [paths objectAtIndex:0]; // NSString *file = [documentsDirectory stringByAppendingPathComponent:@"capturas.sqlite"]; // NSData *data=[NSData dataWithContentsOfFile:file]; 

And replace the following

  NSString *path = [[NSBundle mainBundle] pathForResource:@"database name without extension" ofType:@"sqlite"]; NSData *myData = [NSData dataWithContentsOfFile:path]; [composer addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:path]; [self presentModalViewController:composer animated:YES]; } else { UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:@"No se a podido mandar el mensage" delegate:self cancelButtonTitle:@"dismis" otherButtonTitles:nil, nil]; [alert show]; } 

}

+9
source

All Articles