嘿,我正在使用此代码从我的应用程序中发送电子邮件
@IBAction func sendEmail(_ sender: Any) {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["test@gmail.com"])
composeVC.setSubject("Feedback")
composeVC.setMessageBody("", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil) //CRASHES
}
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult, error: Error?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
该应用程序已上线,来自用户的电子邮件确实会发送给我。除了“从我的 iPhone 发送”之外,它们通常是空的,但我认为这不是编程问题。什么是一个问题,显然,上周,由于“//CRASHES”行,8 个设备丢弃了崩溃报告。
我认为模拟器在尝试执行此操作时会崩溃,但我已经数周没有使用模拟器进行此安装,因此 iTunesConnect 上的那些崩溃报告是合法的崩溃。
如果用户没有安装电子邮件应用程序会怎样?
最佳答案
您可以通过调用验证用户是否已设置发送邮件的设备
[MFMailComposeViewController canSendMail]
在执行任何操作之前
关于iOS Swift 3 存在 MFMailComposeViewController 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46991393/