ios - MFMailComposeViewController 不会关闭
<p><p>我的应用中有以下代码用于发送电子邮件:</p>
<pre><code>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)
}
</code></pre>
<p>我似乎无法让 MFMailComposeViewController 关闭,我做错了什么??</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>一般不调用委托(delegate)方法时:<br/>
• 检查是否设置了代理。你正确地使用 <code>mc.mailComposeDelegate = self</code><br/>
• 检查您设置的委托(delegate)方法是否符合协议(protocol)。<br/>
• 检查委托(delegate)方法是否在您作为委托(delegate)传递的对象中正确实现(这就是您的问题所在)。阅读文档,或删除方法声明,让编译器/IDE/XCode 为您自动完成它。在各种教程之间的 Swift 中,它们经常出现问题,因为 Swift 1、Swift 2、Swift 3/4 已重命名方法并导致问题,教程仅关注 Swift 版本。</p>
<p>你的方法:</p>
<pre><code>func mailComposeController(_ controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?)
</code></pre>
<p><a href="https://developer.apple.com/documentation/messageui/mfmailcomposeviewcontrollerdelegate/1616880-mailcomposecontroller" rel="noreferrer noopener nofollow">documentation</a> 中的方法:</p>
<pre><code>func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
</code></pre>
<p>由于它们不一样,iOS SDK 应该检查委托(delegate)是否响应正确的方法,那么你的不应该被调用,因为它不匹配。</p></p>
<p style="font-size: 20px;">关于ios - MFMailComposeViewController 不会关闭,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/48168807/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/48168807/
</a>
</p>
页:
[1]