我现在搜索了至少 2 个小时,但找不到答案。
我需要一个类型的对象CNContact
。我发现CNContactViewController
这个视图完全符合我的要求。有了它,我可以使用预定义的视图创建一个新联系人,这给了我一个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)
}
谢谢你的帮助!