Swift3.0 访问通讯录

来源:互联网 发布:手机指南针软件 编辑:程序博客网 时间:2024/05/20 22:00
  • iOS10中 ABPeoplePickerNavigationController()已被弃用,现在使用的是CNContactPickerViewController, 注意在info.plist中加上访问权限Privacy - Contacts Usage Description ,value自行设定
//第一步,引入import ContactsUI//第二步,代理CNContactPickerDelegateoverride func viewDidLoad() {        super.viewDidLoad()  let pickerVC = CNContactPickerViewController()  pickerVC.delegate = self  //在需要的地方present出来即可  self.present(pickerVC, animated: true, completion: nil)    }//代理方法--可获得姓名,电话,邮箱等信息func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {        PrintLog(contact.familyName) //姓        PrintLog(contact.givenName) //名        PrintLog(contact.phoneNumbers)        for i in contact.phoneNumbers {            let phoneNum = i.value.stringValue //电话号码            PrintLog(phoneNum)        }    }//其他代理方法自行发掘
1 0
原创粉丝点击