如果联系人属性与ios8有多个电话号码,则显示联系人属性

Lee*_*eep 5 abpeoplepickerview ios ios8

在ios8中,我想访问联系人属性,如果他有多个号码电话,但我不知道如何在iOS8中这样做.

这是我在iOS7中的代码:

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{

    //If person has just one phone number
    ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    if(ABMultiValueGetCount(phonesRef) == 1){

        CPIContact* contact = [self getCPIContactFromPerson:person andPhoneIndex:0];
        [self addContact:contact];

        // Dismiss the address book view controller.
        [_addressBookController dismissViewControllerAnimated:YES completion:nil];
        return NO;

    }else if(ABMultiValueGetCount(phonesRef) == 0){

        [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Common_information",nil) message:NSLocalizedString(@"EditCallSMS_noNumber", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Common_ok",nil) otherButtonTitles:nil] show];

        return NO;
    }
    else{
        return YES;
    }

}
Run Code Online (Sandbox Code Playgroud)

我知道我必须使用iOS8中的didSelectPerson方法,但我不知道如何告诉应用程序在选择像iOS7这样的人之后可以继续.

我在Apple文档中读到了关于predicateForSelectionOfPerson但我不明白如何使用它.

https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/ABPeoplePickerNavigationController_Class/index.html#//apple_ref/occ/instp/ABPeoplePickerNavigationController/predicateForSelectionOfProperty

预先感谢您的帮助.

rma*_*ddy 10

在实例化人员选择器的地方添加:

if ([peoplePicker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)])
{
     peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"%K.@count > 1", ABPersonPhoneNumbersProperty];
}
Run Code Online (Sandbox Code Playgroud)

这样,您只能选择包含2个或更多电话号码的联系人.对于其他联系人,您将看到联系方式.