0

私はMFMailComposeViewControllerdempアプリに実装しています。しかし、何らかの理由で、タッチしてメール テキスト フィールドにテキストを追加すると、アプリがクラッシュします。ただし、テキストを追加せずに送信すると問題なく動作します。

Xcode があまり表示されません。ここに私が得ているものがあります:

ここに画像の説明を入力

メールのテキスト フィールドに既に初期テキストを設定しています。多分問題はここにありますか?コードをリクエストしてください。喜んで含めます。

更新: ここでは、最初のメソッドopenMailが起動する2つのメソッドがUIButton

- (IBAction)openMail:(id)sender
{
    if ([MFMailComposeViewController canSendMail])
    {

    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }

    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

        mailer.mailComposeDelegate = self;

        [mailer setSubject:@"Feedback from Demo App user"];

        NSArray *toRecipients = [NSArray arrayWithObjects:@"myEMAIL@hotmail.com", @"myEMAIL2@gmail.com", nil];
        [mailer setToRecipients:toRecipients];

        NSString *emailBody = @"Happy to hear your feedback!";
        [mailer setMessageBody:emailBody isHTML:NO];

        [self presentModalViewController:mailer animated:YES];

        [mailer release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
            break;
        default:
            NSLog(@"Mail not sent.");
            break;
    }

    // Remove the mail view
    [self dismissModalViewControllerAnimated:YES];
}
4

2 に答える 2

0

おそらくあなたは ARC を使用していて、あなたへの強力なポインタを持っておらずMFMailComposeViewController、ディスプレイの後、ARC はそれを解放しています。

使用する

@property (nonatomic,stron) MFMailComposeViewController *mail;

MFMailComposeViewController を初期化する場合:

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
self.mail = mailer;
于 2012-09-01T19:56:53.377 に答える
0

コードに次の行がまだありますか?

[mailer release];

もしそうなら、それが問題です。そうでない場合は、コード サンプルを更新して、現在使用しているものとまったく同じになるようにしてください。

于 2012-09-01T23:06:02.693 に答える