在MFMailComposeViewController不能按取消或发送按钮后,予以驳回。我已经添加MFMailComposeViewControllerDelegate了课程,但是仍然无法正常工作吗?
这是我的代码:
func sendEmail() {
let MailVC = MFMailComposeViewController()
MailVC.mailComposeDelegate = self
MailVC.setToRecipients(["\(emailLabel?.text)"])
MailVC.setSubject("Set your subject here!")
MailVC.setMessageBody("Hello this is my message body!", isHTML: false)
// Present the view controller modally.
self.present(MailVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) 我在收到我提出的电子邮件时遇到了困难.
电子邮件打开很好,但一旦打开它就不会关闭mailComposeController:mailer didFinishWithResult:结果错误:错误处理程序永远不会被调用.
据我所知,我已经掌握了所有可以做到这一点.
任何有关我能看到什么的想法?
以下是我如何提出电子邮件:
-(IBAction)emailButtonPressed
{
Run Code Online (Sandbox Code Playgroud)
NSString*text = @"我的电子邮件文本";
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.delegate = self;
[mailer setSubject:@"Note"];
[mailer setMessageBody:text isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
Run Code Online (Sandbox Code Playgroud)
然后在类中我有这个代码来处理close(但它永远不会被调用):
-(void)mailComposeController:(MFMailComposeViewController *)mailer didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self becomeFirstResponder];
[mailer dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我的头文件定义为:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface myViewController : UIViewController <UIActionSheetDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>
Run Code Online (Sandbox Code Playgroud)
谢谢
Iphaaw
delegates ×1
email ×1
ios ×1
iphone ×1
mfmailcomposeviewcontroller ×1
objective-c ×1
swift3 ×1