XCode8 Swift3 - Problems with open contact list and retrieve data by click
Asked Answered
L

1

8

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. 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.

This is the Button code

@IBAction func addNewContactOnClick(_ sender: AnyObject) {

        let peoplePicker = CNContactPickerViewController()

        peoplePicker.delegate = self

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

CNContactPickerDelegate methods

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")
}
Lumpish answered 6/10, 2016 at 10:29 Comment(0)
P
8

Methods of CNContactPickerDelegate is changed in Swift 3 like below.

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

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

For other methods of CNContactPickerDelegate check Apple Documentation.

Pepys answered 6/10, 2016 at 10:31 Comment(2)
Thanks. Now, I only need to retrieve the data I want and finally this will work again...Lumpish
Welcome mate :)Pepys

© 2022 - 2024 — McMap. All rights reserved.