如果安装了Mail功能,如果没有打开应用程序商店页面

时间:2017-07-19 10:31:19

标签: ios swift email url url-scheme

我正在尝试做标题所说的内容,但是当我点按按钮打开邮件时,我的应用程序在我没有安装邮件应用程序时崩溃。你可以帮我解决这个问题吗?

代码:

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{

1 个答案:

答案 0 :(得分:2)

试试这种方式

datepicker-options="{showWeeks:false,minDate:today}"

original post here