How to read phone book number labels?

I know how to get a phone number from ABRecordRef , but now I want to get the type of number, i.e. its label as a string:

 const CFStringRef kABPersonPhoneIPhoneLabel; const CFStringRef kABPersonPhoneMainLabel; const CFStringRef kABPersonPhoneHomeFAXLabel; const CFStringRef kABPersonPhoneWorkFAXLabel; const CFStringRef kABPersonPhonePagerLabel; 

This is how I get the numbers:

 //get all phone numbers NSArray *phoneNumbersArray = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty); NSInteger numbersCounter = 0; for(numbersCounter = 0; numbersCounter < [phoneNumbersArray count]; numbersCounter++) { NSString currentPhoneNumber = [phoneNumbersArray objectAtIndex:indexPhoneNumber]; // here i would like to read the type of phone number // NSLog(@"NumberType:%@",numberType); } 

I tried all kinds of things and I read the ABPerson Handbook and I don’t know how to get the type of phone number?

+4
source share
2 answers

I figured out how to read a localized phone number label

 //get all phone numbers ABMultiValueRef phoneNumberMultiValue = ABRecordCopyValue(currentPerson, kABPersonPhoneProperty); NSUInteger phoneNumberIndex; for (phoneNumberIndex = 0; phoneNumberIndex < ABMultiValueGetCount(phoneNumberMultiValue); phoneNumberIndex++) { CFStringRef labelStingRef = ABMultiValueCopyLabelAtIndex (phoneNumberMultiValue, phoneNumberIndex); NSString *phoneLabelLocalized = (NSString*)ABAddressBookCopyLocalizedLabel(labelStingRef); NSString *phoneNumber = (NSString *)ABMultiValueCopyValueAtIndex(phoneNumberMultiValue, phoneNumberIndex); //memory management [phoneLabelLocalized release]; [phoneNumber release]; CFRelease(labelStingRef); } 
+15
source

Here is a code snippet that a person creates, adds 2 phone contacts, and then shows how to get to the label and value for the phone property:

 ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType); ABMultiValueIdentifier multivalueIdentifier; ABMultiValueAddValueAndLabel(multi, @"(555) 555-1234", kABPersonPhoneMobileLabel, &multivalueIdentifier); ABMultiValueAddValueAndLabel(multi, @"(555) 555-2345", kABPersonPhoneMainLabel, &multivalueIdentifier); ABRecordRef aRecord = ABPersonCreate(); CFErrorRef anError = NULL; ABRecordSetValue(aRecord, kABPersonPhoneProperty, multi, &anError); CFRelease(multi); multi = ABRecordCopyValue(aRecord, kABPersonPhoneProperty); for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) { CFStringRef phoneNumber, phoneNumberLabel; phoneNumberLabel = ABMultiValueCopyLabelAtIndex(multi, i); phoneNumber = ABMultiValueCopyValueAtIndex(multi, i); NSLog(@"%@ %@", (NSString *) phoneNumberLabel, (NSString *) phoneNumber); CFRelease(phoneNumberLabel); CFRelease(phoneNumber); } CFRelease(aRecord); CFRelease(multi); 

In code, it iterates over all multi-valued values ​​and extracts the label and number as they are used, using ABMultiValueCopyLabelAtIndex and ABMultiValueCopyValueAtIndex respectively.

+2
source

Source: https://habr.com/ru/post/1393932/


All Articles