[英]Presenting MFMessageComposeViewController/Understanding DispatchQueue.main.async
我想在一个人选择他们的联系人后提出MFMessageComposeViewController
。 但是我收到以下消息的lldb
错误-
***由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图以模态形式呈现活动控制器<Indexex.PortfolioSettingsViewController:0x1452000000>。”
这是我的代码:
func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
var recipients = [String]()
//-- select contacts and present message compose view controller
contacts.forEach { (contact) in
for data in contact.phoneNumbers {
let phoneNo = data.value
recipients.append(phoneNo.stringValue)
}
//-- configure message view controller
messageViewController.recipients = recipients
messageViewController.body = "Testing Testing"
//-- reload the view controller
DispatchQueue.main.async {
self.present(self.messageViewController, animated: true, completion: nil)
}
}
}
我对调度队列的了解不是很深,所以我将对它和线程进行更多的研究,但是如果有人愿意帮助我,将不胜感激。
问题是您试图同时显示每个选定联系人的消息控制器。 你不能那样做。 您一次只能显示一个。 您是否真的要显示多个消息控制器,每个联系人一个,还是所有联系人一个消息?
由于您尝试呈现多个MFMessageComposeViewController
, MFMessageComposeViewController
,如果您想在外部for循环中调用一个,如下所示:
contacts.forEach { (contact) in
for data in contact.phoneNumbers {
let phoneNo = data.value
recipients.append(phoneNo.stringValue)
}
}
//-- configure message view controller
messageViewController.recipients = recipients
messageViewController.body = "Testing Testing"
//-- reload the view controller
DispatchQueue.main.async {
self.present(self.messageViewController, animated: true, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.