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

后端 未结 2 1096
猫巷女王i
猫巷女王i 2021-02-10 15:40

I\'d like to get a list of all ABContacts that have a phone number and only those contacts. Any contacts with just an email I do not want to show.

Android has a field ca

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 16:14

    You can use this code snippet

    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
        }
    }
    

提交回复
热议问题