IPhone Address Book: How to get a list of only contacts with phone numbers?

I would like to get a list of all ABContacts that have a phone number and only those contacts. Any contact with email that I don’t want to show.

Android has a HAS_PHNONE_NUMBER field that you can request for, but I don’t see anything like it for the iPhone.

For instance:

ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook); //How do I filter people into an array of contacts that all have a phone number? 
+4
source share
2 answers

You can use this piece of code

 CFIndex numberOfPeople = CFArrayGetCount(_allPeople); for (int i=0;i < numberOfPeople;++i) { ABRecordRef ref = CFArrayGetValueAtIndex(_allPeople, i); ABMultiValueRef phones =(NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty); int phoneNumbersCount = ABMultiValueGetCount(phones); if (phoneNumbersCount>0) { // save this contact, it has phone number } } 
+8
source

There is no easy way or help in iOS, so you need to parse your array, and if the people you disassembled have a phone number or the list of phone numbers is not empty, you add it to your last array.

+2
source

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


All Articles