我正在尝试从新的联系人框架 iOS 9 中获取选择的电子邮件地址,但我找不到正确的解决方案。电话号码和姓名工作正常。
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
}