我正在尝试做标题所说的内容,但是当我点按按钮打开邮件时,我的应用程序在我没有安装邮件应用程序时崩溃。你可以帮我解决这个问题吗?
private async Task GenerateToken(HttpContext context)
{
var username = context.Request.Form["username"];
var password = context.Request.Form["password"];
// The rest of the method
}
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{