Display contact properties if it has more than one phone number with ios8

In ios8, I would like to access the properties of a contact if it has more than one phone number, but I don’t know how to do it in iOS8.

Here is my code in 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; } } 

I know that I need to use the didSelectPerson method from iOS8, but I do not know how to tell the application that it can continue after selecting a person, as in iOS7.

I read about predicateForSelectionOfPerson on Apple documentation, but I don't understand how to use it.

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

Thank you in advance for your help.

+5
source share
1 answer

Add this when you instantiate the people picker:

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

This will allow you to select contacts with two or more phone numbers. For other contacts you will be shown contact details.

+10
source

Source: https://habr.com/ru/post/1203414/


All Articles