• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - MFMailComposeViewController 不会关闭

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:25:31 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我的应用中有以下代码用于发送电子邮件:

let ToRecipents = ["recipient here"]
        let subject = "subject here"
        let MessageBody = "message here"

        let mc : MFMailComposeViewController = MFMailComposeViewController()

        mc.mailComposeDelegate = self


        mc.setToRecipients(ToRecipents)
        mc.setSubject(subject)
        mc.setMessageBody(MessageBody, isHTML: false)

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

    }

    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {

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

    }

我似乎无法让 MFMailComposeViewController 关闭,我做错了什么??



Best Answer-推荐答案


一般不调用委托(delegate)方法时:
• 检查是否设置了代理。你正确地使用 mc.mailComposeDelegate = self
• 检查您设置的委托(delegate)方法是否符合协议(protocol)。
• 检查委托(delegate)方法是否在您作为委托(delegate)传递的对象中正确实现(这就是您的问题所在)。阅读文档,或删除方法声明,让编译器/IDE/XCode 为您自动完成它。在各种教程之间的 Swift 中,它们经常出现问题,因为 Swift 1、Swift 2、Swift 3/4 已重命名方法并导致问题,教程仅关注 Swift 版本。

你的方法:

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?)

documentation 中的方法:

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)

由于它们不一样,iOS SDK 应该检查委托(delegate)是否响应正确的方法,那么你的不应该被调用,因为它不匹配。

关于ios - MFMailComposeViewController 不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48168807/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap