我有一个使用VoIP集成的CallKit应用程序。
在我的联系人屏幕中,我有一个包含所有设备联系人的UITableView,当用户按下联系人时,我用以下内容填充一个CNContactViewController:
extension ContactsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectedContact = viewModel.contactAt(section: indexPath.section, index: indexPath.row)
Logd(self.logTag, "\(#function) \(String(describing: selectedContact))")
let contactViewController = CNContactViewController(for: selectedContact!)
contactViewController.title = CNContactFormatter.string(from: selectedContact!,
style: CNContactFormatterStyle.fullName)
contactViewController.contactStore = viewModel.contactStore
contactViewController.allowsActions = false
contactViewController.delegate = self
navigationItem.titleView = nil
navigationController?.pushViewController(contactViewController, animated: true)
tableView.deselectRow(at: indexPath, animated: false)
}
}这将填充“联系人详细信息”视图,没有任何问题。
我想捕捉电话号码上的用户操作,按下并执行VoIP呼叫,所以我使用以下代码:
extension ContactsViewController: CNContactViewControllerDelegate {
func contactViewController(_ viewController: CNContactViewController,
shouldPerformDefaultActionFor property: CNContactProperty) -> Bool {
if property.key == CNContactPhoneNumbersKey {
let phoneNumberProperty: CNPhoneNumber = property.value as! CNPhoneNumber
let phoneNumber = phoneNumberProperty.stringValue
makeMyVoIPCall(number: phoneNumber!, video: false)
//makeMyVoIPCall(number: "+1234567890", video: false)
return false
}
if property.key == CNContactSocialProfilesKey {
let profile: CNSocialProfile = property.value as! CNSocialProfile
if profile.service == appServiceName {
let phoneNumber = profile.username
makeMyVoIPCall(number: phoneNumber!, video: false)
return false
}
}
Logd(self.logTag, "\(#function) nothing to handle for \(property)")
return true
}
func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
dismiss(animated: true, completion: nil)
}
}这有一个结果,当我按下电话项目元素,以启动2个电话!一个调用是从我的应用程序(VoIP)执行的,另一个是从系统(SIM/GSM)执行的。
我试过的是:
CNContactSocialProfilesKey的代码,在这种情况下,调用只按预期通过我的应用程序执行一次。需要什么才能告诉系统我正在处理操作,而SIM/GSM呼叫不应该执行?
我正在iOS 12.1.1 (16C50)上进行测试。
发布于 2019-01-07 18:58:14
将makeMyVoIPCall(number: phoneNumber!, video: false)封装在主线程包中解决了这个问题。
我真的不明白为什么iOS会忽略false值。
https://stackoverflow.com/questions/54041982
复制相似问题