我正试着按照标题所说的做,但当我点击按钮打开邮件时,我的应用程序在没有安装邮件应用程序的情况下崩溃了。你能帮我解决这个问题吗?
代码:
if UIApplication.shared.canOpenURL(URL(string: "mailto://")!) {
// Mail is installed. Launch Mail and start function:
let toRecipients = ["oExample@gmail.com"]
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setToRecipients(toRecipients)
mc.setSubject("Why does it crash?")
mc.setMessageBody("×©× ××ר: \(CrashNameField.text!) \n\n×¢×ר: \(CrashReasonNameField.text!)", isHTML: false)
self.present(mc, animated: true, completion: nil)
}else {
// Mail is not installed. Launch AppStore to install Mail app
UIApplication.shared.openURL(URL(string: "https://itunes.apple.com/gb/app/mail/id1108187098?mt=8")!)
}
}
libc++abi.dylib: terminating with uncaught exception of type NSException
在线崩溃:
class AppDelegate: UIResponder, UIApplicationDelegate{
.额外信息:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target