Does ABPeoplePickerNavigationController change with iOS8?

Since I updated Xcode (6.0, 6A313) and my iOS (8.0, 12A365) on iPhone seeds to gm, the code ABPeoplePickerNavigationController does not work as before.

  • iOS 7.1.2 If someone wants to import a contact, the address book will open and you will see a complete list of contacts, after selecting one of them a detailed view of the contact will open, and you can add a contact by clicking on the phone number you want to import.

  • iOS 8.0: it all looks like it, but if you click on a contact number, dial the phone number and not import it.

the code:

#pragma mark - AddressBook Delegate Methods -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ return YES; } -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{ // Get the first and the last name. Actually, copy their values using the person object and the appropriate // properties into two string variables equivalently. // Watch out the ABRecordCopyValue method below. Also, notice that we cast to NSString *. NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); NSString *lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); // Compose the full name. NSString *fullName = @""; // Before adding the first and the last name in the fullName string make sure that these values are filled in. if (firstName != nil) { fullName = [fullName stringByAppendingString:firstName]; } if (lastName != nil) { fullName = [fullName stringByAppendingString:@" "]; fullName = [fullName stringByAppendingString:lastName]; } // Get the multivalue number property. CFTypeRef multivalue = ABRecordCopyValue(person, property); // Get the index of the selected number. Remember that the number multi-value property is being returned as an array. CFIndex index = ABMultiValueGetIndexForIdentifier(multivalue, identifier); // Copy the number value into a string. NSString *number = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multivalue, index); nameTextField.text = fullName; numberTextField.text = number; // Dismiss the contacts view controller. [_addressBookController dismissViewControllerAnimated:YES completion:nil]; return NO; } // Implement this delegate method to make the Cancel button of the Address Book working. -(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{ [_addressBookController dismissViewControllerAnimated:YES completion:nil]; } 

could not find the answer in the iOS developer library for Apple. Does anyone else have a solution for this?

+47
ios ios8 abpeoplepickerview
Sep 12 '14 at 10:59
source share
3 answers

iOS 8 requires a new delegate method for this:

 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { } 

Keep the old delegation method to support iOS 7 or earlier. What I do in my application calls the iOS 7 delegate method from the iOS 8 delegate method:

 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier]; } 

If this delegate method is not implemented in iOS 8, clicking on the value triggers an action. When implemented, the delegate is called instead with the selected value.

+78
Sep 12 '14 at 16:08
source share

See also delegate method new with iOS8:

 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person; { [self selectedPerson:person]; } 

This is what I wanted in my case.

+13
Sep 20 '14 at 4:09
source share

This worked for me on both iOS 8 and iOS 7 and below.

Note. Instead, I use this didSelectPerson: (ABRecordRef).

 //Needed for iOS 8 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person { NSLog(@"Went here 1 ..."); [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person]; } //needed for iOS 7 and lower - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { NSLog(@"Went here 2 ..."); //add your logic here } 
+1
Dec 27 '14 at 18:05
source share



All Articles