【问题标题】:Error sending database from xCode从 xCode 发送数据库时出错
【发布时间】:2012-07-15 01:04:20
【问题描述】:

我正在尝试从我的 iphone 应用程序发送附加到邮件的 sqlite 数据库,我收到了电子邮件但没有收到数据库文件,对不起我的语法,我来自西班牙,这是我的代码。

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

【问题讨论】:

    标签: iphone xcode ipad sqlite email


    【解决方案1】:

    我认为你应该使用:

    application/x-sqlite3 代替 mimeType 的 application/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];
    }   
    

    }

    【讨论】:

    • 还将 isHTML: 设置为 NO,如果不起作用,您可以查看此链接以供参考 (principalhuman.com/content/…)
    • 在上面但还是没有结果,错误必须在这一行 [composer addAttachmentData:data mimeType:@"application/x-sqlite" fileName:@"capturas.sqlite"];跨度>
    • 我没有看到代码有问题,所以我建议检查常见错误,例如未在项目树中添加文件或检查文件扩展名,..etc
    • 检查了一切,数据库在那里,我可以添加字段,它是一个 sqlite 文件等,不知道该怎么做。
    • 请检查上面的解决方案
    猜你喜欢
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多