1

私はクライアント用の iPad アプリを持っていますが、アプリに機能を追加して、ボタンをクリックして電子メール プログラムを起動し、問題の診断のためにアプリで使用される sqlite データベースを送信できるようにする必要があります。アップルのサンプルアプリに従ったところ、うまくいきました。dbファイルが添付されたメールが送信されました。電子メールからファイルをダウンロードして 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
}
4

1 に答える 1

1

投稿したコードは、アプリのリソース バンドルからデータベース ファイルを読み取っています。これは、もともとアプリに付属していた読み取り専用ファイルです。

実際のデータを含む書き込み可能なデータベース ファイルを取得する必要があります。おそらく、これは Documents ディレクトリ (またはその他の書き込み可能なサンドボックス ディレクトリ) にあります。

ところで - なぜMFMailComposeViewControllerクラスをチェックしているのですか? iOS 3.0から存在しています。アプリが iOS 2.x (または 3.x) をサポートする必要があるとは思えません。

于 2013-01-12T01:56:29.867 に答える