简体   繁体   English

XCode8 Swift3 - 打开联系人列表并通过单击检索数据的问题

[英]XCode8 Swift3 - Problems with open contact list and retrieve data by click

Currently I'm developing my first iOS App and I'm a little slow and rude about the code (it's so weird and different from java) and, if this was the only problem, with the new update, Xcode is making my code insane. 目前我正在开发我的第一个iOS应用程序,我对代码有点慢和粗鲁(它是如此奇怪,与java不同),如果这是唯一的问题,新的更新,Xcode使我的代码疯狂。 I think I solved most of the issues but... 我想我解决了大部分问题,但......

Before, on one of the screens, the app opened a the address book and let the user click on one; 之前,在其中一个屏幕上,应用程序打开了一个地址簿,让用户点击一个; when the clicked was done, the contact list close and data from that contact was retrieved to the controller. 点击完成后,联系人列表关闭,该联系人的数据被检索到控制器。 Now, if the user click on a contact, more info is displayed but any information come out of the console log. 现在,如果用户单击某个联系人,则会显示更多信息,但任何信息都会从控制台日志中显示出来。

I try everything I find on net and I'm not sure why is not working. 我尝试在网上找到的所有内容,但我不确定为什么不起作用。

Before, I use Addressbook (or something like that) but I already tried with CNContact . 以前,我使用Addressbook (或类似的东西),但我已经尝试过使用CNContact

This is the Button code 这是Button代码

@IBAction func addNewContactOnClick(_ sender: AnyObject) {

        let peoplePicker = CNContactPickerViewController()

        peoplePicker.delegate = self

        self.present(peoplePicker, animated: true, completion: nil)
    }

CNContactPickerDelegate methods CNContactPickerDelegate方法

func contactPicker(picker: CNContactPickerViewController, didSelectContacts contacts: [CNContact]){
        contacts.forEach { contact in
            for number in contact.phoneNumbers {
                let phoneNumber = number.value as! CNPhoneNumber
                print("number is = \(phoneNumber)")
            }
        }
    }

func contactPickerDidCancel(picker: CNContactPickerViewController) {
    print("Cancel Contact Picker")
}

Methods of CNContactPickerDelegate is changed in Swift 3 like below. CNContactPickerDelegate方法在Swift 3中更改,如下所示。

func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
    //your code
}

func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
    //your code
}

For other methods of CNContactPickerDelegate check Apple Documentation . 对于CNContactPickerDelegate其他方法, CNContactPickerDelegate检查Apple文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM