如何仅使用 CNContactViewController 来创建新联系人? (Swift)

How to use CNContactViewController just for creating new contacts? (Swift)

我有一个应用程序需要添加联系人。为此,我想使用 ContactsUI 框架中的 CNContactViewController(forNewContact: nil)。

我的实现方法如下

class myClass: UITableViewController, CNContactViewControllerDelegate {
    // ...
    @objc fileprivate func addTapped() {
        print("add tapped")

        let createContactcontroller = CNContactViewController(forNewContact: nil)
        controller.delegate = self

        navigationController?.pushViewController(controller, animated: true)
    }

    func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
        // Service.shared.addContact(contact: contact)
    }

}

但是有几个问题我解决不了:

  1. 动画看起来很慢。
  2. 当用户完成创建联系人并完成点击后,配置文件的 CNContactViewController(如在联系人应用程序中) 被显示,而不是仅仅返回到 tableViewController。我该如何修改它?

  1. 我收到以下错误:

2019-11-16 10:29:48.480636+0100 Flashback[11688:541742] [Snapshotting] Snapshotting a view (0x7fc76481a420, _UIButtonBarStackView) that has not been rendered at least once requires afterScreenUpdates:YES. 2019-11-16 10:29:48.482425+0100 Flashback[11688:541742] [Snapshotting] Snapshotting a view (0x7fc76481d020, _UIButtonBarStackView) that has not been rendered at least once requires afterScreenUpdates:YES. 2019-11-16 10:29:48.484897+0100 Flashback[11688:541742] [Snapshotting] Snapshotting a view (0x7fc76481d5c0, _UIButtonBarStackView) that has not been rendered at least once requires afterScreenUpdates:YES. 2019-11-16 10:29:48.488071+0100 Flashback[11688:541742] [Snapshotting] Snapshotting a view (0x7fc76481d9f0, _UIButtonBarStackView) that has not been rendered at least once requires afterScreenUpdates:YES. 2019-11-16 10:29:48.489883+0100 Flashback[11688:541742] [Snapshotting] Snapshotting a view (0x7fc7626228e0, _UIButtonBarStackView) that has not been rendered at least once requires afterScreenUpdates:YES. 2019-11-16 10:29:48.491904+0100 Flashback[11688:541742] [Snapshotting] Snapshotting a view (0x7fc7626102d0, _UIButtonBarStackView) that has not been rendered at least once requires afterScreenUpdates:YES.

您使用的这个视图控制器有误。

您不能将其推送到现有的视图控制器上。相反,您使用 CNContactViewController 作为其根视图控制器实例化 UINavigationController,并且 present 导航控制器作为呈现的视图控制器。然后,您必须在 contactViewController(_:didCompleteWith:).

的实现中自行关闭显示的导航控制器

还要注意这个错误,它使这个视图控制器基本上无法使用:

Keyboard overlaying action sheet in iOS 13.1 on CNContactViewController