avoid CNContactPickerViewController to show emails

↘锁芯ラ 提交于 2019-12-25 07:15:09

问题


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
     ];

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?

I also used:

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

But it is not working too.


回答1:


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




回答2:


If you only want to show phone numbers for the contact when you select the contact, use the displayedPropertyKeys property:

self.contactPicker.displayedPropertyKeys = @[CNContactPhoneNumbersKey];

But if you don't want to even be able to select those contacts who don't have phone numbers, you'd want to set predicateForEnablingContact:

self.contactPicker.predicateForEnablingContact = [NSPredicate predicateWithFormat:@"%K.@count > 0", CNContactPhoneNumbersKey];

I notice that you're using self.contactPicker.predicateForSelectionOfContact. But what if the person has multiple phone numbers? Which one are you going to use? Personally, I'd be inclined to not set that property at all, or if you wanted to, perhaps allow the user to drill in and choose the desired phone number if there were multiple phone numbers:

self.contactPicker.predicateForSelectionOfContact = [NSPredicate predicateWithFormat:@"%K.@count == 1", CNContactPhoneNumbersKey];


来源:https://stackoverflow.com/questions/39700966/avoid-cncontactpickerviewcontroller-to-show-emails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!