【问题标题】:sqlite database no data after emailed from within iPad app从 iPad 应用程序发送电子邮件后,sqlite 数据库没有数据
【发布时间】:2013-01-11 20:23:18
【问题描述】:

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

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
}

【问题讨论】:

    标签: ios ipad sqlite


    【解决方案1】:

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

    您需要获取包含实际数据的可写数据库文件。也许您在 Documents 目录(或其他可写沙箱目录)中有这个。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 2023-04-07
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 1970-01-01
      相关资源
      最近更新 更多