加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 将sqlite附加到xcode邮件

发布时间:2020-12-14 18:05:52 所属栏目:百科 来源:网络整理
导读:我对这段代码感到很疯狂,它应该可以工作,但是当我收到邮件时没有附加文件,这是我的代码: -(IBAction)mandar:(id)sender{ MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init]; [composer setMailComposeDelegate:self]; if (
我对这段代码感到很疯狂,它应该可以工作,但是当我收到邮件时没有附加文件,这是我的代码:

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

但不知道为什么它不起作用,thx的帮助

解决方法

我已经更新了答案: Error sending database from xCode但似乎你没有检查它,无论如何这里它又是:

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

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读