let customLabel = String (stringInterpolationSegment: ABAddressBookCopyLocalizedLabel(locLabel))
This will print a phone number label. I believe that this is what you are looking for, for more details, please visit here . Find the full code below.
EDIT
let status = ABAddressBookGetAuthorizationStatus()
if status == .Denied || status == .Restricted {
return
}
var error: Unmanaged<CFError>?
let addressBook: ABAddressBook? = ABAddressBookCreateWithOptions(nil, &error)?.takeRetainedValue()
if addressBook == nil {
println(error?.takeRetainedValue())
return
}
ABAddressBookRequestAccessWithCompletion(addressBook) {
granted, error in
if !granted {
return
}
if let people = ABAddressBookCopyArrayOfAllPeople(addressBook)?.takeRetainedValue() as? NSArray {
for record:ABRecordRef in people {
var phones : ABMultiValueRef = ABRecordCopyValue(record,kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
for(var numberIndex : CFIndex = 0; numberIndex < ABMultiValueGetCount(phones); numberIndex++)
{
let phoneUnmaganed = ABMultiValueCopyValueAtIndex(phones, numberIndex)
let phoneNumber : NSString = phoneUnmaganed.takeUnretainedValue() as! NSString
let locLabel : CFStringRef = (ABMultiValueCopyLabelAtIndex(phones, numberIndex) != nil) ? ABMultiValueCopyLabelAtIndex(phones, numberIndex).takeUnretainedValue() as CFStringRef : ""
var cfStr:CFTypeRef = locLabel
var nsTypeString = cfStr as! NSString
var swiftString:String = nsTypeString as String
let customLabel = String (stringInterpolationSegment: ABAddressBookCopyLocalizedLabel(locLabel))
println("Name :-\(swiftString) NO :-\(phoneNumber)" )
}
}
}
}
: Swift - 4 BadCode.
func getAllContactPhoneNumber() {
let phones: ABMultiValue = ABRecordCopyValue(person,
kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValue
for numberIndex in 0..<ABMultiValueGetCount(phones) {
let phoneUnmaganed = ABMultiValueCopyValueAtIndex(phones, numberIndex)
guard let phoneNumber = phoneUnmaganed!.takeUnretainedValue() as? NSString else {
return
}
let locLabel: NSString = (ABMultiValueCopyLabelAtIndex(phones, numberIndex) != nil) ?
ABMultiValueCopyLabelAtIndex(phones, numberIndex).takeUnretainedValue() as NSString: ""
let cfStr: CFTypeRef = locLabel
guard let nsTypeString = cfStr as? NSString else {
return
}
let swiftString: String = nsTypeString as String
let customLabel = String (stringInterpolationSegment: ABAddressBookCopyLocalizedLabel(locLabel))
print("Name :-\(swiftString) NO :-\(phoneNumber)" )
}
}
Name :-_$!<Mobile>!$_ NO :-8592-841222
Name :-CUSTOMLABEL NO :-111
Name :-_$!<Home>!$_ NO :-45445
- ,
, _$!< .