iPhone地址簿:如何获得电话号码的联系人列表? [英] iPhone Address Book: How to get a list of only contacts with phone numbers?

查看:169
本文介绍了iPhone地址簿:如何获得电话号码的联系人列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望得到所有具有电话号码的AB联系人列表,只有这些联系人。只有电子邮件的任何联系人我不想显示。

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_PHNONE_NUMBER的字段,您可以查询,但是我没有看到类似iPhone的任何内容。

Android has a field called HAS_PHNONE_NUMBER you can query on but I'm not seeing anything like that for iPhone.

例如:

For example:

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


推荐答案

您可以使用此代码片段

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

这篇关于iPhone地址簿:如何获得电话号码的联系人列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆