Swift 3通过电话和电子邮件信息添加新联系人 [英] Swift 3 add new contact with phone and email information
本文介绍了Swift 3通过电话和电子邮件信息添加新联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试提示用户创建新联系人并传递信息。 (特别是电话和电子邮件)
I'm trying to prompt the user to create a new contact and pass in information. (specifically a phone and email)
我发现了许多使用CNMutableContact并向其添加电子邮件的示例。但是,任何涉及CNContact的代码都会给我一个使用未声明的类型错误。
I've found numerous examples of using a CNMutableContact and adding an email to it. However, any of the code involving the CNContact gives me a "Use of undeclared type" error.
如何设置我的班级以提示用户保存联系人?
How can I setup my class to prompt the user to save the contact?
推荐答案
func addPhoneNumber(phNo : String) {
if #available(iOS 9.0, *) {
let store = CNContactStore()
let contact = CNMutableContact()
let homePhone = CNLabeledValue(label: CNLabelHome, value: CNPhoneNumber(stringValue :phNo ))
contact.phoneNumbers = [homePhone]
let controller = CNContactViewController(forUnknownContact : contact)
controller.contactStore = store
controller.delegate = self
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationController!.pushViewController(controller, animated: true)
}
}
这篇关于Swift 3通过电话和电子邮件信息添加新联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文