Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In ios8, I would like to access contact properties if he has more than one numberphone 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 I have to use the method didSelectPerson from iOS8 but I don't know how to tell the app that it can continue after selecting a person like 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.

like image 367
Leep Avatar asked Sep 25 '14 15:09

Leep


1 Answers

Add this where you instantiate the people picker:

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

This will only let you choose contacts with 2 or more phone numbers. For other contacts, you will be shown the contact details.

like image 82
rmaddy Avatar answered Nov 06 '22 23:11

rmaddy