2017-07-19 3 views
2

私はタイトルに記載されていることをしようとしていますが、メールアプリケーションをインストールしていないときに私のアプリケーションがクラッシュします。これを整理する手助けはできますか?Mailがインストールされている場合Do関数がない場合はOpen app storeページ

コード:ライン上の

libc++abi.dylib: terminating with uncaught exception of type NSExceptionクラッシュ:class AppDelegate: UIResponder, UIApplicationDelegate{

if UIApplication.shared.canOpenURL(URL(string: "mailto://")!) { 
      // Mail is installed. Launch Mail and start function: 
      let toRecipients = ["[email protected]"] 

     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")!) 
     } 
    } 

クラッシュログを収集しました。余分な情報:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target

+0

この方法を試してみてください?どのラインがクラッシュするのですか? – Paulw11

+0

申し訳ありませんが、 'libC++ abi.dylib:NSException型のキャッチされていない例外で終了すると、' class AppDelegate:UIResponder、UIApplicationDelegate {'がクラッシュします。追加情報: 'キャッチされていない例外のためにアプリケーションを終了させる 'NSInvalidArgumentException'、理由: 'アプリケーションがターゲット上にnilモーダルビューコントローラを表示しようとしたとき' – RandomGeek

+0

' mc == nil'を確認するだけです。 – Paulw11

答えて

2

は、クラッシュは何

var picker = MFMailComposeViewController() 
    if MFMailComposeViewController.canSendMail() { 
     picker.mailComposeDelegate = self 
     picker.setSubject("Test mail") 
     picker.setMessageBody(messageBody.text, isHTML: true) 
     present(picker as? UIViewController ?? UIViewController(), animated: true) { _ in } 
    } 

original post here

+0

Iアプリがインストールされていない場合はアラートを表示するかリンクを開いてクラッシュしないようにする必要がありますか? – RandomGeek

+0

これ以外の条件では、このUIApplication.shared.openURL(URL(文字列: "https://itunes.apple.com/gb/app/mail/id1108187098?mt=8")を入れてください!) –

+0

これはコードです。 ...そのまだ – RandomGeek

関連する問題