iOS Swift 3 存在 MFMailComposeViewController 导致崩溃

标签 ios iphone

嘿,我正在使用此代码从我的应用程序中发送电子邮件

@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 上的那些崩溃报告是合法的崩溃。

如果用户没有安装电子邮件应用程序会怎样?

enter image description here

最佳答案

您可以通过调用验证用户是否已设置发送邮件的设备

[MFMailComposeViewController canSendMail]

在执行任何操作之前

关于iOS Swift 3 存在 MFMailComposeViewController 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46991393/

相关文章:

ios - 如何在 UIMenuController 的指定位置添加自定义 menuItem?

c# - iOS、Android、Windows 10 移动模拟器是否可用于使用 Visual Studio 2015 开发 Xamarin.Forms?

ios - iOS 设备上的葫芦测试启动应用程序但卡住在 "Scenario"

iphone - 捆绑 ID 后缀?它是什么?

iOS:将资源(音频)文件包含到应用程序的应用程序文件夹中,而不是添加到 bundle 中

iphone - 在 iPhone 的照片库中写入 UIImage 以及元数据(EXIF、GPS、TIFF)

ios - 无法将 codegen 设置到 CoreData 中

ios - iPhone 5s Touch ID 传感器 API

iphone - ios 6 : issue - Two-stage rotation animation is deprecated. 这个应用应该使用更流畅的单阶段动画

iphone - 隐藏 UIAlertView