我对这段代码感到疯狂,它应该可以工作,但是当我收到邮件时没有附加文件,这是我的代码:
-(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];
}
}
路径没问题,数据库中有数据,我在撰写邮件时也看到了该文件,但没有任何东西到达我的邮件。我想问题就在这里
[composer addAttachmentData:data mimeType:@"application/x-sqlite3" fileName:@"capturas.sqlite"];
但不知道为什么它不起作用,谢谢帮助