ios - CNContactViewController setEditing true before appear

标签 ios swift contacts cncontactviewcontroller

我有一个任务是在他出现的时候(比如WhatsApp)立刻显示联系人编辑界面,我用下面的方式显示给他。

   @objc private func presentContactEditController() {
        guard var contact = contactModel.contact else { return }
        if !contact.areKeysAvailable([CNContactViewController.descriptorForRequiredKeys()]) {
            do {
                let contactStore = CNContactStore()
                contact = try contactStore.unifiedContact(withIdentifier: contact.identifier, keysToFetch: [CNContactViewController.descriptorForRequiredKeys()])
            } catch {
                debugPrint("presentContactEditController error", error.localizedDescription)
            }
        }
        let cnContactViewController = CNContactViewController(for: contact)
        cnContactViewController.delegate = self
        cnContactViewController.setEditing(true, animated: false)

        let contactNaviController = UINavigationController(rootViewController: cnContactViewController)
        present(contactNaviController, animated: true, completion: nil)
    }

但是有一个屏幕显示有关此联系人的信息。所以我尝试通过CNContactViewController的继承者来实现,不同的方法ViewController生命周期,但是它只在viewDidAppear方法中起作用,但是它会对用户可见。我怎么解决这个问题?谢谢。

最佳答案

只需更改 let cnContactViewController = CNContactViewController(for: contact)

let cvc = CNContactViewController(forNewContact: contact)

它会为你工作

关于ios - CNContactViewController setEditing true before appear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41922058/

相关文章:

ios - 弹出现有 View Controller 并加载父 View Controller

ios - 从相机拍摄的 iphone 图像自动旋转 -90 度

swift - 无法将返回表达式类型转换为带有闭包的返回类型?

ios - 在推送动画期间在输入附件 View 中显示文本的奇怪延迟。

android - 在android ListView 中获取联系人姓名和生日

IOS蓝牙BLE写值返回 "Unknown error"

ios - 在 iOS App 中显示播放列表文件夹

ios - SWRevealController点击事件不起作用,而滑动背景效果很好

PHP/JavaScript? 10 分钟内只允许提交两次?

javascript - 仅当创建新联系人/帐户时才使用 JavaScript 解锁 CRM 2011 字段