从xCode发送数据库时出错

时间:2012-07-16 07:40:01

标签: iphone xcode ipad sqlite email

我正在尝试从我的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];
    }
}

1 个答案:

答案 0 :(得分:0)

我认为你应该使用:

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

}