I'm trying to fetch picked email address from new contact framework iOS 9 but I cannot find right solution. Phone number and name working fine.
func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) {
let phoneNumberString: String
let emailString: String
let contact = contactProperty.contact
let contactName = CNContactFormatter.stringFromContact(contact, style: .FullName) ?? ""
let propertyName = CNContact.localizedStringForKey(contactProperty.key)
let message = "Picked \(propertyName) for \(contactName)"
if(propertyName == "Phone") {
let phoneNumber = contactProperty.value as! CNPhoneNumber
//print(contact.givenName)
phoneNumberString = phoneNumber.stringValue ?? ""
inputPhone.text = phoneNumberString.regexPatern("[0-9]+").joinWithSeparator(" ")
}
if(propertyName == "Email") {
I need email address //print(email contact)
}
inputName.text = contact.givenName
inputSurname.text = contact.familyName
// Display only a person's phone, email, and birthdate
let displayedItems = [CNContactPhoneNumbersKey, CNContactEmailAddressesKey, CNContactBirthdayKey]
picker.displayedPropertyKeys = displayedItems
}