如何将新联系人添加到联系人

我的应用程序中有一个“ +”按钮,点击时,我想导航到“新联系人”屏幕(如下图所示)。

如何将新联系人添加到联系人

我在这里找到了相同的问题:iOS - add contact into Contacts?,但是代码不是最新的。 我想要Swift 5中的解决方案。

shanlovehua 回答:如何将新联系人添加到联系人

import Contacts      // import these framework
import ContactsUI

//--- Your Button Action
@IBAction func buttonClick(_ sender: Any)
{
    let openContact = CNContact()
    let vc = CNContactViewController(forNewContact: openContact)
     vc.delegate = self // this delegate CNContactViewControllerDelegate
   // self.navigationController?.pushViewController(vc,animated: true)
   self.present(UINavigationController(rootViewController: vc),animated:true)
}


func contactViewController(_ viewController: CNContactViewController,didCompleteWith contact: CNContact?) {

    self.dismiss(animated: true,completion: nil)
}
本文链接:https://www.f2er.com/3144585.html

大家都在问