Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MFMailComposeViewController拒绝解雇_Ios_Swift_Mfmailcomposeviewcontroller_Mfmailcomposer - Fatal编程技术网

Ios MFMailComposeViewController拒绝解雇

Ios MFMailComposeViewController拒绝解雇,ios,swift,mfmailcomposeviewcontroller,mfmailcomposer,Ios,Swift,Mfmailcomposeviewcontroller,Mfmailcomposer,这让我快发疯了。这段代码允许用户发送一封包含应用程序中创建的图像的电子邮件。除了self.disclose(动画:true,完成:nil)之外,所有功能都可以正常工作,MFMailComposeViewController不会关闭 我用这三个可能的问题作为解决问题的起点,但它仍然不起作用。尽管已发送邮件或点击了cancel,但控制器仍保持不变 添加了协议实现MFMailComposeViewControllerDelegate func mailOpen(alertAction: UIAlert

这让我快发疯了。这段代码允许用户发送一封包含应用程序中创建的图像的电子邮件。除了
self.disclose(动画:true,完成:nil)
之外,所有功能都可以正常工作,
MFMailComposeViewController
不会关闭

我用这三个可能的问题作为解决问题的起点,但它仍然不起作用。尽管已发送邮件或点击了
cancel
,但控制器仍保持不变

添加了协议实现
MFMailComposeViewControllerDelegate

func mailOpen(alertAction: UIAlertAction) {
    if MFMailComposeViewController.canSendMail() {
        let mailcontroller = MFMailComposeViewController()
        mailcontroller.mailComposeDelegate = self;
        mailcontroller.setSubject("Subject")
        let completeImage = newImage! as UIImage
        mailcontroller.addAttachmentData(UIImageJPEGRepresentation(completeImage, CGFloat(1.0))!, mimeType: "image/jpeg", fileName: "Image")
        mailcontroller.setMessageBody("<html><body><p>Message</p></body></html>", isHTML: true)

        self.present(mailcontroller, animated: true, completion: nil)
    } else {
        let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send the e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "Got it!")
        sendMailErrorAlert.show()
    }

    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
        self.dismiss(animated: true, completion: nil)
    }
}//end of mail
func mailOpen(alertAction:UIAlertAction){
如果MFMailComposeViewController.canSendMail(){
让mailcontroller=MFMailComposeViewController()
mailcontroller.mailComposeDelegate=self;
mailcontroller.setSubject(“主题”)
让completeImage=newImage!作为UIImage
mailcontroller.addAttachmentData(UIImageJPEGresentation(completeImage,CGFloat(1.0))!,mimeType:“image/jpeg”,文件名:“image”)
mailcontroller.setMessageBody(“Message

”,isHTML:true) self.present(mailcontroller,动画:true,完成:nil) }否则{ 让sendMailErrorAlert=UIAlertView(标题:“无法发送电子邮件”,消息:“您的设备无法发送电子邮件。请检查电子邮件配置并重试。”,委托:self,取消按钮提示:“收到了!”) sendMailErrorAlert.show() } func mailComposeController(u控制器:MFMailComposeViewController,未完成结果:MFMailComposeResult,错误:NSError?){ self.disclose(动画:true,完成:nil) } }//邮件结束
问题是您已经在
mailOpen
函数中编写了
didFinishWithResult:
delegate方法,因此它永远不会被调用,也永远不会执行解除代码

func mailOpen(alertAction: UIAlertAction)
{
    if MFMailComposeViewController.canSendMail()
    {
        let mailcontroller = MFMailComposeViewController()
        mailcontroller.mailComposeDelegate = self;
        mailcontroller.setSubject("Subject")
        let completeImage = newImage! as UIImage
        mailcontroller.addAttachmentData(UIImageJPEGRepresentation(completeImage, CGFloat(1.0))!, mimeType: "image/jpeg", fileName: "Image")
        mailcontroller.setMessageBody("<html><body><p>Message</p></body></html>", isHTML: true)

        self.present(mailcontroller, animated: true, completion: nil)

    }
    else
    {

        let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send the e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "Got it!")
        sendMailErrorAlert.show()
    }
}//end of mail

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?)
{
    self.dismiss(animated: true, completion: nil)
}
func mailOpen(alertAction:UIAlertAction)
{
如果MFMailComposeViewController.canSendMail()
{
让mailcontroller=MFMailComposeViewController()
mailcontroller.mailComposeDelegate=self;
mailcontroller.setSubject(“主题”)
让completeImage=newImage!作为UIImage
mailcontroller.addAttachmentData(UIImageJPEGresentation(completeImage,CGFloat(1.0))!,mimeType:“image/jpeg”,文件名:“image”)
mailcontroller.setMessageBody(“Message

”,isHTML:true) self.present(mailcontroller,动画:true,完成:nil) } 其他的 { 让sendMailErrorAlert=UIAlertView(标题:“无法发送电子邮件”,消息:“您的设备无法发送电子邮件。请检查电子邮件配置并重试。”,委托:self,取消按钮提示:“收到了!”) sendMailErrorAlert.show() } }//邮件结束 func mailComposeController(u控制器:MFMailComposeViewController,未完成结果:MFMailComposeResult,错误:NSError?) { self.disclose(动画:true,完成:nil) }
此处:

self.disclose(动画:true,完成:nil)

您正在关闭自己的ViewController,而不是
MFMailComposeViewController

应该是:

controller.dismiss(animated: true, completion: nil)

开口大括号不应被包装(请参阅)。@PEEJWEEJ没有理由编辑某人的答案,只是为了更改大括号的位置。不同的人喜欢不同的风格。@deville:没有官方文件规定应该遵循哪种风格。我更喜欢这种风格,因为它很容易与开合支架匹配。谢谢!愚蠢的错误