ios - 我可以在不将联系人保存到 contactStore 的情况下使用 View CNContactViewController 吗?

标签 ios swift cncontact cncontactviewcontroller

我现在搜索了至少 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/

相关文章:

ios - 快速更改 contactUI 'forNewContact' 的标题

ios - Dropbox sdk 401 Error getting for iPhone 5 but not in iPhone 6 for the same app in Xcode 6

ios - iOS5 应用程序中 Facebook 的 Hackbook 集成

ios - 是否可以通过接口(interface)生成器从父类(super class)更改约束的常量值?

regex - Swift - 正则表达式匹配引号中的任何内容

ios9 - 更改 CNContactPickerViewController iOS 的导航栏颜色

ios - 使用联系人框架创建新组,CNErrorDomain Code = 2

ios - 如何在 Swift 中每隔 X 秒重复一次?

ios - 表中的 iPhone SQLite 跟踪分数

嵌入式 WebView OSX 中未显示 Javascript 警报