从xCode发送数据库时出错 [英] Error sending database from xCode

查看:147
本文介绍了从xCode发送数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

   - (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆