2013-01-11 23 views
1

我必须为我的客户的iPad应用程序,现在我需要添加应用功能,他们可以点击一个按钮,将邮件程序和发送使用他们的SQLite数据库由应用程序给我的问题诊断。我跟着苹果的示例应用程序,它运行良好。我收到了附带的db文件发送的电子邮件。从电子邮件下载文件并在SQLite Manager(Firefox)中打开它之后,所有表格模式都是正确的,但是没有数据。有谁知道问题是什么?我下载的db文件与设备的大小完全一样。谢谢。SQLite数据库没有从iPad应用程序内通过电子邮件发送后数据

Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 

if (mailClass != nil) 
{ 

    // check whether the current device is configured for sending emails 

    if ([mailClass canSendMail]) 
    { 
     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
     picker.mailComposeDelegate = self; 

     [picker setSubject:@"database file from ios app"]; 


     // Set up recipients 
     NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

     [picker setToRecipients:toRecipients]; 

     // Attach db file to the email 
     NSString *path = [[NSBundle mainBundle] pathForResource:@"MyDB" ofType:@"sqlite"]; 
     NSData *myData = [NSData dataWithContentsOfFile:path]; 
     [picker addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:@"MyDB.sqlite"]; 

     // Fill out the email body text 
     NSString *emailBody = @"test email with db"; 

     [picker setMessageBody:emailBody isHTML:NO]; 
     picker.modalPresentationStyle = UIModalPresentationFormSheet; 
     [self presentModalViewController:picker animated:YES]; 

     [picker release]; 
    } 
    else // email not configured 
    { 
     // Alert email is not configured 
    } 
} 
else // older iOS 
{ 
     // Alert OS is too old 
} 

回答

1

您发布的代码是从应用程序的资源包中读取数据库文件。这是最初随应用程序一起提供的只读文件。

你需要得到有实际数据写入数据库文件。也许你在Documents目录(或其他一些可写的沙箱目录)中有这个。

顺便说一句 - 你为什么要为MFMailComposeViewController类检查?它自iOS 3.0起就已存在。我怀疑你的应用需要支持iOS 2.x(甚至是3.x)。

+0

非常感谢!我会尝试不同的事情来弄清楚。我稍后会回来标记你的答案。你是对的,我可能不需要支持任何低于3.0的东西,这只是一个很好的做法,我借用了苹果示例应用程序中的代码。 –

+0

我面临同样的问题,你做完了吗?我可以将sqlite文件附加到邮件中,但我永远无法通过MAC上的LiYa应用程序打开它 – ikzjfr0

相关问题