2012-07-16 83 views
0

我想從我的iphone應用程序發送附加到郵件的sqlite數據庫,我收到電子郵件但不是數據庫文件,對我的語法抱歉,我來自西班牙,這是我的代碼。從xCode發送數據庫時出錯

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

回答

0

我認爲你應該使用:

應用程序/ x-sqlite3的,而不是爲mime類型

編輯應用程序/ 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]; 
} 

}

+0

仍然一無所獲=替換( – user1528181 2012-07-16 07:46:31

+0

還設置isHTML:爲NO,如果沒有工作,你可以檢查這個鏈接引用(http://principalhuman.com/composer addAttachmentData:data mimeType:@「application/x-content-sending-email-attachment-using-apple-iphone-sdk-xcode-40) – XIII 2012-07-16 07:51:38

+0

但仍然沒有結果,錯誤必須在這一行[ sqlite「fileName:@」capturas.sqlite「]; – user1528181 2012-07-16 08:04:32