ios - 初始化 MFMessageComposeViewController 时应用程序崩溃

标签 ios swift mfmessagecomposeviewcontroller

我想通过我的应用程序发送消息。我在点击时调用以下方法

@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 中运行它时:崩溃日志清楚地指出 “在这种情况下仅支持 RGBA 或白色颜色空间。” 所以我会提示说您正在某处分配颜色 (Some Global tint, navigation bar tint) ,它不适用于 MFMessageComposeViewController,因此会崩溃。

当你在模拟器中运行它时:

如果 (MFMessageComposeViewController.canSendText()),此行将阻止它在模拟器中初始化 MFMessageComposeViewController,因为它无法发送文本,因此当您尝试呈现它,它尚未初始化并且正在崩溃。

再想一想,根据您的代码:self.presentViewController(composeVC, animated: true, completion: nil),在模拟器中运行时甚至不应该调用这一行在 if 语句中,不会通过。

还可以在初始化 Controller 时更改色调颜色或任何颜色,并告诉我结果是什么。

关于ios - 初始化 MFMessageComposeViewController 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48495708/

相关文章:

ios - Swift 将图像附加到 iMessage

带有 AFNetworking 的 iOS POST 请求

iphone - 是否可以使用 Microsoft 管理的 EWS 通过 MonoTouch 构建 iPhone 应用程序?

ios - 无法使用类型为“([T.Type],来自 : Data) 的参数列表调用 'decode'

macos - 如何在 OSX Mavericks 上呈现 ViewControllerAsSheet?

ios - MFMessageComposeViewController 栏透明

ios - 从第一个 ViewController 到第二个 ViewController 的图像

ios - 检测 UITextField 自动建议文本替换

swift - “Int”无法转换为 'Range<Int>'

iphone - 通过 Iphone 发送短信,MFMessageComposeViewController