Fetch localized phone label using Contacts frameworks
use CNLabeledValue
s class method + localizedStringForLabel:
and pass the label
example:
CNLabeledValue *phoneNumberValue = contact.phoneNumbers.firstObject;
NSString *label = phoneNumberValue.label;
label = [CNLabeledValue localizedStringForLabel:label];
NSLog(@"Phone Label: %@",label); //Logs value like home
add this line Contact Access
if contact.isKeyAvailable(CNContactPhoneNumbersKey){
for phoneNumber:CNLabeledValue in contact.phoneNumbers {
let number = phoneNumber.value
let number2 = number.stringValue
let lable :String = CNLabeledValue<NSString>.localizedString(forLabel: phoneNumber.label! )
print("\(lable) \(number.stringValue)")
}
}
And here it is in Swift 3:
let displayNumbers = contact.phoneNumbers.map() {
let label = CNLabeledValue<NSString>.localizedString(forLabel: $0.label ?? "")
return label + ": \u{200E}" + $0.value.stringValue
}
Added unicode LeftToRight override, to ensure the number is not reversed on RTL languages.