我现在搜索了至少 2 个小时,但找不到这个问题的答案。
我需要一个 CNContact
类型的对象。我找到了 CNContactViewController
,这个 View 完全符合我的要求。有了它,我可以使用预定义 View 创建一个新联系人,这为我提供了一个 CNContact
对象。
这是我的问题:
CNContactViewController
将创建的联系人保存到 contactStore
。但我不想要这个。我可以抑制这种行为吗?我很确定一定有解决方案。
这是我创建 ViewController
的代码:
let contactController = CNContactViewController(forNewContact: nil)
contactController.allowsEditing = true
contactController.allowsActions = false
contactController.displayedPropertyKeys = [CNContactPostalAddressesKey, CNContactPhoneNumbersKey, CNContactGivenNameKey]
contactController.delegate = self
contactController.view.layoutIfNeeded()
let navigationController = UINavigationController(rootViewController: contactController)
self.present(navigationController, animated: true)
在这里我想使用通讯录中没有的联系人:
func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
viewController.navigationController?.dismiss(animated: true)
}
感谢您的帮助!
最佳答案
But I don't want this. Can I suppress this behavior? I'm pretty sure there must be a solution.
没有。如果用户保存了编辑过的联系人(点击完成),那么当你听到它时,它已经保存到联系人数据库中,你无能为力。
当然你可以右转并删除已保存的联系人。但是你不能阻止储蓄从一开始就发生。
关于ios - 我可以在不将联系人保存到 contactStore 的情况下使用 View CNContactViewController 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54897295/