Iphone 将sqlite附加到xcode邮件
我对这段代码非常着迷,它应该可以工作,但当我收到邮件时,没有附加任何文件,以下是我的代码:Iphone 将sqlite附加到xcode邮件,iphone,database,xcode,sqlite,email,Iphone,Database,Xcode,Sqlite,Email,我对这段代码非常着迷,它应该可以工作,但当我收到邮件时,没有附加任何文件,以下是我的代码: -(IBAction)mandar:(id)sender { MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init]; [composer setMailComposeDelegate:self]; if ([MFMailComposeViewController canS
-(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"];
但是我不知道为什么它不起作用,谢谢你的帮助。我已经在更新了答案:但是你似乎没有检查它,不管怎样,它还是在这里:
-(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];
从您的代码中注释了以下内容:
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// NSString *documentsDirectory = [paths objectAtIndex:0];
// NSString *file = [documentsDirectory stringByAppendingPathComponent:@"capturas.sqlite"];
// NSData *data=[NSData dataWithContentsOfFile:file];
并替换为以下内容
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];
}
}您可以附加sqlite文件,但您永远无法打开它,例如,通过MacFund上的LiYa应用程序。。。此处列出了
-(void)addAttachmentData:(NSData*)附件mimeType:(NSString*)mimeType文件名:(NSString*)文件名所支持的mime类型。没有应用程序/x-sqlite3
类型。将在真实环境中尝试该代码。这是否能够附加.db文件?是的,只要您更改文件名、扩展名和mimeType(在这种情况下应为application/octet-stream),并且该文件可以被iOS读取,它就应该能够附加任何文件。请在尝试后给出反馈,以便其他用户可以在需要时找到答案。SQLITE中的数据为空。您可以将此解决方案的swift版本发布到@XIII吗