【发布时间】:2017-02-21 13:45:03
【问题描述】:
我希望在我的应用程序https://www.youtube.com/watch?v=HKCXwm7r838 中使用这个过程。但是本教程中的代码是针对旧版 IOS 的,我使用的是 IOS 10、Xcode 8.2、Swift 3.0,所以它不适合我。我尝试了以下代码来显示联系人列表。它有效。
import UIKit
import ContactsUI
class ViewController: UIViewController, CNContactPickerDelegate{
@IBOutlet weak var textLabel: UILabel!
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func addExistingContact()
{
}
func contactPicker(picker: CNContactPickerViewController, didSelectContact contacts: CNContact)
{
// print(contacts.givenName)
}
@IBAction func button(_ sender: Any)
{
let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
contactPicker.displayedPropertyKeys =
[CNContactGivenNameKey
, CNContactPhoneNumbersKey]
self.present(contactPicker, animated: true, completion: nil)
}
func contactPickerDidCancel(picker: CNContactPickerViewController)
{
print("Cancel Contact Picker")
}
}
现在,我想要的是,当我从列表中选择任何联系人姓名时,联系人列表必须立即消失,然后选择的姓名和号码必须显示在 viewController 中的两个标签/文本字段中。有人可以告诉我应该使用什么代码吗?提前致谢。
【问题讨论】: