簡體   English   中英

MFMessageComposeViewController初始化時,應用崩潰

[英]App crash when MFMessageComposeViewController is initialisation

我想通過我的應用發送消息。 我點擊以下方法

@IBAction func sendMessage(_ sender: Any) {
     if (MFMessageComposeViewController.canSendText()) {
         let composeVC = MFMessageComposeViewController()
         composeVC.messageComposeDelegate = self

         // Configure the fields of the interface.
         composeVC.recipients = ["4085551212"]
         composeVC.body = "Hello from California!"

         // Present the view controller modally.
         self.presentViewController(composeVC, animated: true, completion: nil)
     }
}

問題是,如果我在設備上運行應用程序,它將在MFMessageComposeViewController初始化時崩潰,即

let composeVC = MFMessageComposeViewController()

如果我在模擬器中運行該應用,它將在演示時崩潰,即

self.present(composeVC, animated: true, completion: nil)

在設備上運行應用程序時出現錯誤日志

2018-01-29 12:03:57.826816+0530 EWS[2495:806400] *** Assertion failure in -[UICGColor encodeWithCoder:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.33.7/UIColor.m:1722
2018-01-29 12:03:57.827522+0530 EWS[2495:806400] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.'
*** First throw call stack:
(0x183702364 0x182948528 0x183702238 0x18409d7f4 0x18d08fffc 0x1840574dc 0x18405e8d8 0x18d4ebf20 0x18d4eb74c 0x18d4e7044 0x1835d03c0 0x18d4e6d44 0x18d7f16fc 0x18d60bd18 0x18d60b94c 0x19aee4534 0x19aecbff4 0x19aecc314 0x1984ce830 0x101159ec0 0x101158888 0x1011584b4 0x1011589c0 0x18cc186b4 0x18cc18634 0x18cc031dc 0x18cc17f28 0x18cc17a48 0x18cc12f60 0x18cbe3f64 0x18d53931c 0x18d53b8a8 0x18d5347c0 0x1836aa97c 0x1836aa8fc 0x1836aa184 0x1836a7d5c 0x1835c7e58 0x185474f84 0x18cc4767c 0x101157170 0x1830e456c)
libc++abi.dylib: terminating with uncaught exception of type NSException

當我在模擬器上運行應用程序時出現錯誤日志(不檢查if(MFMessageComposeViewController.canSendText())

2018-01-29 12:07:49.395714+0530 EWS[3533:67163] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <EWS.BlockVC: 0x7f899c61db10>.'
*** First throw call stack:

任何幫助,將不勝感激。

好的,

在iPhone中運行它時 :崩潰日志明確指出"Only RGBA or White color spaces are supported in this situation.""Only RGBA or White color spaces are supported in this situation." 因此,通過提示,我想說的是您正在某處分配顏色((某些全局色調,導航欄色調)),該顏色不適用於MFMessageComposeViewController,因此會崩潰。

在模擬器中運行它時:

if (MFMessageComposeViewController.canSendText()) ,此行將阻止它在模擬器中初始化MFMessageComposeViewController ,因為它無法發送文本,因此,當您嘗試呈現它時,它尚未初始化並崩潰。

再考慮一下,根據您的代碼: self.presentViewController(composeVC, animated: true, completion: nil) ,即使在模擬器中運行,也不應調用此行,因為該行位於if語句內,該行不會通過。

還要在初始化控制器時更改色調顏色或任何其他顏色,然后告訴我結果是什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM