从xCode发送数据库时出错 [英] Error sending database from xCode
问题描述
- (IBAction)mandar:(id)sender
{
MFMailComposeViewController * composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if([MFMailComposeViewController canSendMail])
{
[composer setToRecipients:[NSArray arrayWithObjects:@Introducir directccion,nil]];
[composer setSubject:@Base de datos];
[作曲家setMessageBody:@Mensage是HTML: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 / sqlitefileName:@capturas.sqlite];
[self presentModalViewController:composer animated:YES];
}
else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@Errormessage:@No se a podido mandar el mensagedelegate:self cancelButtonTitle:@dismis otherButtonTitles:nil,nil];
[alert show];
}
}
认为您应该使用:
应用程序/ x-sqlite3而不是应用程序/ sqlite for mimeType
编辑:解决它并发送文件:
- (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];
[作曲家setMessageBody:@Mensage是HTML: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 :文件];
并替换为以下
NSString * path = [[NSBundle mainBundle] pathForResource:@数据库名称无扩展名ofType:@sqlite];
NSData * myData = [NSData dataWithContentsOfFile:path];
[composer addAttachmentData:myData mimeType:@application / x-sqlite3fileName:path];
[self presentModalViewController:composer animated:YES];
}
else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@Errormessage:@No se a podido mandar el mensagedelegate:self cancelButtonTitle:@dismis otherButtonTitles:nil,nil];
[alert show];
}
}
I am trying to send a sqlite database attached to a mail from my iphone app, I receive the email but not the database file, sorry about my grammar,I am from Spain, here is my code.
-(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];
}
}
I think you should use:
application/x-sqlite3 instead of application/sqlite for mimeType
EDIT: This solved it and sent the file:
-(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];
Commented these from your code:
//NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//NSString *documentsDirectory = [paths objectAtIndex:0];
//NSString *file = [documentsDirectory stringByAppendingPathComponent:@"capturas.sqlite"];
//NSData *data=[NSData dataWithContentsOfFile:file];
And replaced with the following
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];
}
}
这篇关于从xCode发送数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!