避免CNContactPickerViewController显示电子邮件

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

self.contactPicker = [[CNContactPickerViewController alloc] init]; self.contactPicker.delegate = self; self.contactPicker.predicateForSelectionOfContact = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"]; [viewController presentViewController:self.contactPicker animated:YES completion:nil ]; 

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

我也用过:

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

但它不工作。

displayedPropertyKeys使用这个属性来控制所有的字段应该是可见的。

如果您只想在select联系人时显示联系人的电话号码,请使用displayedPropertyKeys属性:

 self.contactPicker.displayedPropertyKeys = @[CNContactPhoneNumbersKey]; 

但是,如果您不想要select那些没有电话号码的联系人,那么您需要设置predicateForEnablingContact

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

我注意到你正在使用self.contactPicker.predicateForSelectionOfContact 。 但是如果这个人有多个电话号码呢? 你打算使用哪一个? 就个人而言,我倾向于根本不设置该属性,或者如果您想要,也许允许用户钻取并select所需的电话号码,如果有多个电话号码:

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