【问题标题】:How to add new contact into Contacts如何将新联系人添加到联系人中
【发布时间】:2019-11-07 13:16:16
【问题描述】:

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

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

【问题讨论】:

  • 答案不是“太旧”。这是不变的。
  • 我的意思是如果你不明白代码不是最新的。谢谢!
  • 代码是最新的,我明白。你看过我给你的文档链接了吗?
  • Α 我已经写过,我想在 Swift 5 中得到答案。感谢您给我的链接。我已经通过@Lalitkumar 得到了我想要的答案

标签: ios swift xcode contacts


【解决方案1】:
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)
}

【讨论】:

  • 代码正在运行,但我在动画上遇到了一个奇怪的“错误”,而且取消按钮也不起作用
  • 我在 vc.delegate = self 上收到错误(无法将类型“ViewController”的值分配给类型“CNContactViewControllerDelegate?”)
  • 我通过在我的控制器上添加 CNContactViewControllerDelegate 来修复它。谢谢!
猜你喜欢
  • 2013-03-15
  • 1970-01-01
  • 2012-08-10
  • 2014-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多