避免CNContactPickerViewController显示电子邮件 [英] avoid CNContactPickerViewController to show emails

查看:136
本文介绍了避免CNContactPickerViewController显示电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在应用程序中显示联系人列表:

I use below code to show contact list in my application:

    self.contactPicker = [[CNContactPickerViewController alloc] init];
    self.contactPicker.delegate = self;
    self.contactPicker.predicateForSelectionOfContact =
    [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];

    [viewController presentViewController:self.contactPicker
                                 animated:YES
                               completion:nil
     ];

该页面显示所有联系人,包括电子邮件。我只想显示数字(不显示电子邮件), NSPredicate CNContactPickerViewController 本身是否有任何选项,仅显示数字?

The page shows all contacts including emails . I want to only show numbers (and no emails) is there any options on the NSPredicate or CNContactPickerViewController itself to show only numbers?

我还使用过:

        self.contactPicker.displayedPropertyKeys = @[@"phoneNumber"];

但是它也不起作用。

推荐答案

displayedPropertyKeys 使用此属性控制应显示所有字段的内容。

displayedPropertyKeys use this property to control what all fields should be visible.

Swift 5.2示例

Swift 5.2 example

let contactViewController = CNContactPickerViewController()
contactViewController.displayedPropertyKeys = [CNContactPhoneNumbersKey]

// ... add delegate, present it, etc.

完整的密钥列表可以在 https://developer.apple.com/上找到。文档/联系人/ contact_keys

A full list of keys can be found at https://developer.apple.com/documentation/contacts/contact_keys.

这篇关于避免CNContactPickerViewController显示电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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