如何将新联系人添加到通讯录
How to add new contact into Contacts
我的应用程序中有一个“+”按钮,当我点击时,我想导航到 "new contact" 屏幕(如下图所示)。
我在这里发现了同样的问题:iOS - add contact into Contacts? 但代码不是最新的。
我想要 Swift 5.
中的解决方案
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)
}
我的应用程序中有一个“+”按钮,当我点击时,我想导航到 "new contact" 屏幕(如下图所示)。
我在这里发现了同样的问题:iOS - add contact into Contacts? 但代码不是最新的。 我想要 Swift 5.
中的解决方案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)
}