试图发送电子邮件,"使用未声明的未识别的MFMailComposeViewController"

Ted*_*tel 7 iphone

我正在尝试在我的应用中发送电子邮件.我正在尝试使用MFMailComposeViewController对象,但收到一条错误消息,称其为"未声明的标识符"

码:

-(IBAction) aContact: (id) sender;
{


    if([MFMailComposeViewController canSendMail]){

        MFMailComposeViewController *mailCtrl = [[[MFMailComposeViewController alloc] init] autorelease];
        [mailCtrl setSubject:@"Your TellaFortune Card Reading"];
        //  [mailCtrl setToRecipients:[NSArray arrayWithObject:@"drblyer@cameosurgery.com"]];
        mailCtrl.mailComposeDelegate = self;

        NSString *send;
        send=[ NSString stringWithFormat: @"%@ %@",content,@"\n \n By www.TellaFortune.com"];
        [mailCtrl setMessageBody: send  isHTML: false];

        [self presentModalViewController:mailCtrl animated:NO];
        //      [mailCtrl release];

    }
    else
    {
        UIAlertView *alert=[[ UIAlertView alloc]
                            initWithTitle:@"Cannot send email"
                            message: @"Please check internet connection and email set up"
                            delegate: self
                            cancelButtonTitle:@"Ok"
                            otherButtonTitles: nil];

        [alert show];
    }

}
Run Code Online (Sandbox Code Playgroud)

小智 19

将框架"MessageUI.framework"导入到您的项目和.h文件中

#import <MessageUI/MessageUI.h>
Run Code Online (Sandbox Code Playgroud)


yak*_*ack 13

对于使用Swift并看到此消息的任何人:

首先转到Xcode中的项目设置,选择Build Phases,然后选择Link Binary with Libraries,并在项目中添加"MessageUI.framework".

然后,在要使用MFMailComposeViewController或实现的Swift文件中MFMailComposeViewControllerDelegate,添加:

import MessageUI
Run Code Online (Sandbox Code Playgroud)