列出带有电话号码的联系人 [英] List contacts with phone numbers

查看:92
本文介绍了列出带有电话号码的联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想(在使用Objective-C的iOS中)获取具有电话号码的联系人,但是我该怎么做?我试图按照下面的代码形成谓词,但显然不起作用。

I'd like to fetch (in iOS using Objective-C) only the contacts that have a phone number, but how can I do that? I'm trying to form the predicate as in the code below, but obviously that doesn't work.

contacts = [contactStore unifiedContactsMatchingPredicate:[NSPredicate predicateWithFormat:@"phoneNumbers <> nil"] keysToFetch:KEYS error:nil];

那么,正确的做法是什么?谢谢您的帮助!

So, what is the correct way of doing this? Thanks for any help!

推荐答案

过滤掉没有电话号码(或其他属性)的联系人不是可能。在文档中,我们读取:

Filtering out the contacts that don't have a phone number (or some other property) is not possible. In the docs we read:


CNContact谓词

CNContact Predicates

匹配联系人的谓词。 您只能将这些谓词用于CNContactStore和CNContactFetchRequest。

Predicates to match contacts. You can only use these predicates with CNContactStore and CNContactFetchRequest.


  • predicateForContactsMatchingName:将谓词返回查找与指定名称匹配的联系人。

  • predicateForContactsWithIdentifiers:返回一个谓词以查找与指定标识符匹配的联系人。

  • predicateForContactsInGroupWithIdentifier:返回一个谓词查找属于指定组成员的联系人。

  • predicateForContactsInContainerWithIdentifier:返回一个谓词以查找指定容器中的联系人。

  • predicateForContactsMatchingName: Returns a predicate to find the contacts matching the specified name.
  • predicateForContactsWithIdentifiers: Returns a predicate to find the contacts matching the specified identifiers.
  • predicateForContactsInGroupWithIdentifier: Returns a predicate to find the contacts that are members in the specified group.
  • predicateForContactsInContainerWithIdentifier: Returns a predicate to find the contacts in the specified container.

此外:


不支持复合谓词。

Compound predicates are not supported.

因此,进行过滤的唯一方法是忽略将没有电话号码的联系人添加到结果数组中。例如,可以在 enumerateContactsWithFetchRequest 的块中完成。

So, the only way to do the filtering would be to omit adding to the result array the contacts with no phone numbers. That could be done, for example, in the block of the enumerateContactsWithFetchRequest.

这篇关于列出带有电话号码的联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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