2

アプリにメール機能を追加しようとしています。MFMailComposeViewController を正しく表示し、件名と本文を事前入力することができますが、何らかの理由で、ユーザーがナビゲーション バーの [キャンセル] または [送信] ボタンをクリックすると、アプリがハングします。の最初の行に NSLog() ステートメントを挿入しましたが、mailComposeController"didFinishWithResult:errorその行はコンソールに出力されません。

MFMailComposeViewController がそのようにハングする原因を知っている人はいますか?

ヘッダーからの私のコードは次のとおりです。

#import "ManagedObjectEditor.h"
#import <MessageUI/MessageUI.h>

@interface MyManagedObjectEditor : ManagedObjectEditor 
    <MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate,
     UINavigationControllerDelegate> {
}

- (IBAction)emailObject;
@end

実装ファイルから:

if ([MFMailComposeViewController canSendMail]) {        
    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.delegate = self;
    [mailComposer setSubject:NSLocalizedString(@"An email from me",
                                               @"An email from me")];
    [mailComposer setMessageBody:emailString
                          isHTML:YES];
    [self presentModalViewController:mailComposer animated:YES];
    [mailComposer release];
}
[error release];
[emailString release];

コールバックからのコードは次のとおりです。

#pragma mark -
#pragma mark Mail Compose Delegate Methods
- (void)mailComposeController:(MFMailComposeViewController *)controller 
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError *)error {
    NSLog(@"in didFinishWithResult:");
    switch (result) {
        case MFMailComposeResultCancelled:
            NSLog(@"cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"sent");
            break;
        case MFMailComposeResultFailed: {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error sending email!",@"Error sending email!")
                                                            message:[error localizedDescription]
                                                           delegate:nil
                                                  cancelButtonTitle:NSLocalizedString(@"Bummer",@"Bummer")
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
            break;
        }
        default:
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

ありがとう!

4

1 に答える 1

6

私もこれに少し慣れました。デリゲートではなく、mailComposeDelegate を設定する必要があります。

于 2010-03-11T19:41:47.180 に答える