1

こんにちは、MFMailComposeViewControllerデリゲートのプロパティで混乱しています。mailer.mailComposeDelegate呼び出しの直後にアプリのクラッシュを設定[self presentModalViewController:mailer animated:YES];するとmailer.delegate、アプリはクラッシュしませんが、メールの送信後にビューを非表示にしたり、ナビゲーションバットボタン「キャンセル」からキャンセルしたりできません。なぜこれが起こるのか行き詰まっています。コードを共有させてください。間違いを犯しているヒントが得られます。

if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    if(mailer)
    {
        mailer.mailComposeDelegate = self;
        //mailer.delegate=self;
        [mailer setSubject:@"What the Buck?"];
        imageData = UIImagePNGRepresentation(screenImgSubCat);        

        [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"testapp"];        
        NSString *emailBody = @"What the Buck?! – www.testapp.com";
        [mailer setMessageBody:emailBody isHTML:NO];
        [self presentModalViewController:mailer animated:YES];
        //[mailer release];

    }
}
}

更新しました

コードを変更して使用mailer.mailComposeDelegate = self;し、この行にコメント [mailer release];を付けても、画像の読み込み中にクラッシュします。これがクラッシュ後に得られる画像です。 ここに画像の説明を入力

4

4 に答える 4

3

.hファイルに追加していますか MFMailComposeViewControllerDelegate

@interface VideoPlayAndSharing : UIViewController
<MFMailComposeViewControllerDelegate>  

ComposerSheet の表示

-(void)displayComposerSheet
{
    if ((videodta.length/1024)/1024 < 25)
    {
        NSLog(@"Video size >> %d",videodta.length/1024);
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;

        [picker setSubject:@"Your subject"];


        // Set up recipients
        NSArray *toRecipients = [NSArray arrayWithObject:@"rajneesh071@gmail.com"];
        NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
        NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];

        [picker setToRecipients:toRecipients];
        [picker setCcRecipients:ccRecipients];
        [picker setBccRecipients:bccRecipients];

        [picker addAttachmentData:videodta mimeType:@"video/mp4" fileName:@"MyPersonalMessage"];

        // Fill out the email body text
        NSString *emailBody = @"Type your message here";
        [picker setMessageBody:emailBody isHTML:NO];
        [self presentModalViewController:picker animated:YES];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Personal Message"
                                                        message:@"Video exceed the limit of 25 MB"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}

およびデリゲート メソッド

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            message.text = @"Result: canceled";
            break;
        case MFMailComposeResultSaved:
            message.text = @"Result: saved";
            break;
        case MFMailComposeResultSent:
            message.text = @"Result: sent";
            break;
        case MFMailComposeResultFailed:
            message.text = @"Result: failed";
            break;
        default:
            message.text = @"Result: not sent";
            break;
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}  

編集

picker.mailComposeDelegateその代理人MFMailComposeViewControllerDelegate

その応答- (void)mailComposeController

picker.delegateその代理人UINavigationControllerDelegate

ナビゲーションコントローラーに応答しない- (void)mailComposeControllerため、キャンセルをクリックしても呼び出されないため、MFMailComposeViewControllerビューが非表示になりません。

于 2012-11-21T10:40:11.653 に答える
0

次の行にコメントしてください [mailer release];

問題の原因だと思います

于 2012-11-21T10:53:13.330 に答える
0

最初に .h ファイルに MFMailComposeViewControllerDelegate デリゲートを追加してから、もう一度確認してください。また、mailer.mailComposeDelegate = self; 正しい方法ではありません mailer.delegate=self もコードで変更してから確認してください。

MessageUI/MFMailComposeViewController.h を .m にインポートし、小なり記号と大なり記号を付けて、MessageUI.framework も追加します。

NSArray *toRecipients = [NSArray arrayWithObject:@"vishal@ldh.01s.in"]; 
[mail setToRecipients:toRecipients];

メッセージ本文を設定する前にこれらの 2 行を追加してから確認してください。

于 2012-11-21T10:45:29.423 に答える