Iphone 实现MFMailComposeViewControllerDelegate并将其添加到viewcontroller

Iphone 实现MFMailComposeViewControllerDelegate并将其添加到viewcontroller,iphone,objective-c,cocoa-touch,email,Iphone,Objective C,Cocoa Touch,Email,我正在尝试设置从我的应用程序中发送电子邮件的功能。我的应用程序基于SpeakHere示例项目,该项目使用一个对象运行其所有UI: 这让我很困惑,我需要如何设置MFMailComposeViewControllerDelegate等 这在某种程度上是一种扩展 有什么帮助吗?我使用完整的示例代码解决了这个问题: - (IBAction)email:(id)sender { if ([MFMailComposeViewController canSendMail]){ MF

我正在尝试设置从我的应用程序中发送电子邮件的功能。我的应用程序基于SpeakHere示例项目,该项目使用一个对象运行其所有UI:

这让我很困惑,我需要如何设置MFMailComposeViewControllerDelegate等

这在某种程度上是一种扩展


有什么帮助吗?

我使用完整的示例代码解决了这个问题:

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

        MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
        mail.mailComposeDelegate = self;
        [mail setSubject:@"Sample Subject"];
        [mail setMessageBody:@"Here is some main text in the email!" isHTML:NO];
        [mail setToRecipients:@[@"testingEmail@example.com"]];

        [self presentViewController:mail animated:YES completion:NULL];
    }else {
        NSLog(@"This device cannot send email");
    }
}

#pragma mark - MFMailComposeViewControllerDelegate

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {

    switch (result) {
        case MFMailComposeResultSent:
            NSLog(@"You sent the email.");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"You saved a draft of this email");
            break;
        case MFMailComposeResultCancelled:
            NSLog(@"You cancelled sending this email.");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed:  An error occurred when trying to compose this email");
            break;
        default:
            NSLog(@"An error occurred when trying to compose this email");
            break;
    }

    [self dismissViewControllerAnimated:YES completion:NULL];
}