Error sending database from xCode

I am trying to send a sqlite database attached to mail from my iphone application, I get a letter, but not a database file, sorry for my grammar, I'm from Spain, here is my code.

-(IBAction)mandar:(id)sender { MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init]; [composer setMailComposeDelegate:self]; if ([MFMailComposeViewController canSendMail]) { [composer setToRecipients:[NSArray arrayWithObjects:@"Introducir direccion",nil]]; [composer setSubject:@"Base de datos"]; [composer setMessageBody:@"Mensage" isHTML:YES]; [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *file = [documentsDirectory stringByAppendingPathComponent:@"capturas.sqlite"]; NSData *data=[NSData dataWithContentsOfFile:file]; [composer addAttachmentData:data mimeType:@"application/sqlite" 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]; } } 
0
source share
1 answer

I think you should use:

application / x-sqlite3 instead of application / sqlite for mimeType

EDIT: this solved it and sent the file:

 -(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]; } 

}

0
source

All Articles