简体   繁体   English

从iPad应用内通过电子邮件发送后,sqlite数据库无数据

[英]sqlite database no data after emailed from within iPad app

I have an iPad app for my clients, and now I need to add a feature in the app that they could click a button to bring the email program and send their sqlite database used by the app to me for problem diagnosing. 我有一个适用于我的客户的iPad应用程序,现在我需要在该应用程序中添加一个功能,使他们可以单击按钮以打开电子邮件程序,并将该应用程序使用的sqlite数据库发送给我,以进行问题诊断。 I followed apple's sample app and it worked fine. 我遵循了苹果的示例应用程序,并且运行良好。 I got the email sent with the attached db file. 我收到了带有附件数据库文件的电子邮件。 After I download the file from email and open it in SQLite Manager(Firefox), all the table schema is correct, however there is no data. 从电子邮件下载文件并在SQLite Manager(Firefox)中打开文件后,所有表架构都是正确的,但是没有数据。 Does anyone know what the problem is? 有人知道问题出在哪里吗? The db file I downloaded has exactly the same size as it was from the device. 我下载的db文件与从设备下载的文件大小完全相同。 Thanks. 谢谢。

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:@"someEmailAddress@gmail.com"];

        [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
}

The code you posted is reading the database file from the app's resource bundle. 您发布的代码正在从应用程序的资源包中读取数据库文件。 This is a read-only file originally shipped with the app. 这是应用程序随附的只读文件。

You need to get the writable database file that has the actual data. 您需要获取具有实际数据的可写数据库文件。 Perhaps you have this in the Documents directory (or some other writable sandbox directory). 也许您在Documents目录(或其他一些可写的沙箱目录)中拥有此文件。

BTW - why are you checking for the MFMailComposeViewController class? 顺便说一句-为什么要检查MFMailComposeViewController类? It has existed since iOS 3.0. 自iOS 3.0起就存在。 I doubt your app needs to support iOS 2.x (or even 3.x). 我怀疑您的应用需要支持iOS 2.x(甚至3.x)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM