2

本当に奇妙なエラー MFMailCompseViewController が表示されます。エラーは「エラー: オブジェクト ファイル内のセクションを指すセクションがアドレスに含まれていません」です。MFMailCompseViewController が終了し、電子メールが実際に送信されると、アプリがクラッシュします。

これは MFMailComposeViewController に固有のもので、単純な View Controller をモーダルに表示しようとしたところ、問題なく終了しました。

以下は、私が calland present mail composer に書いたコードです:

- (void) emailImage:(UIImage *)img {
//verified that the image is being returned correctly
UIImage *img1 = [[_delegate photoBrowser:self photoAtIndex:0] underlyingImage];

MFMailComposeViewController *mfViewController = [[MFMailComposeViewController alloc] init];
mfViewController.mailComposeDelegate = self;

NSString *subject = @"Check out this photo I took - Cap That App";

[mfViewController setSubject:subject];
NSData *imgData = UIImageJPEGRepresentation(img1, 1.0);
[mfViewController addAttachmentData:imgData mimeType:@"image/jpg" fileName:@"photo.jpg"];

NSString *contactMessage = @"\n\n<a href=\"http://www.agilerocket.com\">Sent via Cap That - Available in the Apple App Store</a>";

[mfViewController setMessageBody:contactMessage isHTML:YES];

[self presentViewController:mfViewController animated:YES completion:nil];

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Status:" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] autorelease];

switch (result) {
    case MFMailComposeResultCancelled:
        alert.message = @"You chose not to send the email.";
        break;
    case MFMailComposeResultSaved:
        alert.message = @"Your email was saved as a draft. It has not been sent yet.";
        break;
    case MFMailComposeResultSent:
        alert.message = @"Your email has been sent!";
        break;
    case MFMailComposeResultFailed:
        alert.message = @"There was an error sending the email. Please verify your email is working and try again.";
        break;
    default:
        alert.message = @"You chose not to send the email.";
        break;
}

[self dismissViewControllerAnimated:YES completion:^(void) {
    [alert show];
}];

}

これに関する誰かの助けを前もって感謝します。

4

1 に答える 1

2

HUD でタップ ジェスチャを実行すると、アプリで同じエラーが発生します。私のジェスチャ認識メソッドは、必要なアクションを実行するために HUD のブロック プロパティを使用していますが、クラッシュしている場所があります (ブロック内のコードが実行されません)。どうやらプログラムはそのコードにアクセスできず、何が起こっているのかの手がかりになる可能性のある完了ブロックもあるためです。

私は自分のコードで何か間違ったことをしているとは思いませんし、あなたもそうしていないように見えるので、バグかもしれません。もしかして Xcode (4.4 または 4.5) の開発者プレビューを実行していますか?

編集:私の問題は、コードブロックのプロパティが実行される前に解放されていたことでした。あなたの場合、アラート変数で同様のことが起こった可能性があると思います。アラートの初期化を完了ブロック内に移動してみてください。

編集 2:別の方法として、アラートの初期化の前に__weak(または__unsafe_unretainediOS 4.3 をターゲットにしている場合) を付けてみてください。ARC を使用していない場合は、__block代わりに使用してください。

于 2012-07-24T17:24:32.653 に答える