IOS 6 Xcode 4.5 MFMailComposer崩溃

时间:2012-10-05 10:16:10

标签: xcode crash ios6 mfmailcomposer

如果我按下按钮发送电子邮件,我已将XCode更新为4.5,现在电子邮件功能崩溃了。

我做错了什么?

我在头文件中实现了MessageUI.framework

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface ImpressumViewController : UIViewController <MFMailComposeViewControllerDelegate>

以下是我的按钮代码:

- (IBAction)kontakt:(id)sender {

    MFMailComposeViewController *mailcontroller = [[MFMailComposeViewController alloc] init];
    [mailcontroller setMailComposeDelegate:self];
    NSString *email =@"Youtube@gmail.com";
    NSArray *emailArray = [[NSArray alloc] initWithObjects:email, nil];
    [mailcontroller setToRecipients:emailArray];
    [mailcontroller setSubject:@"Youtube Tutorials"];
    [self presentViewController:mailcontroller animated:YES completion:nil]; }

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    [self dismissViewControllerAnimated:YES completion:nil];



    }

1 个答案:

答案 0 :(得分:0)

您需要在此委托方法中编写以下代码

- (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 the next time the user connects to email");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
            break;
        default:
            NSLog(@"Mail not sent");
            break;
    }

    //[self dismissModalViewControllerAnimated:YES];
}