Unable to select contact on iOS 8

I have a subclass of ABPeoplePickerNavigationController to handle the selection of a contact phone number in my application. Everything works fine on iOS 7 and below.

In iOS 8, however, my ABPeoplePickerNavigationControllerDelegate does not hit when choosing a phone number. Instead, it simply calls this phone number.

I noticed that the method that I used to handle contact selection in iOS 7 ( peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier: was deprecated in iOS 8. This method was replaced by peoplePickerNavigationController:didSelectPerson:property:identifier:

I know that my delegate is installed because I successfully receive a callback to the peoplePickerNavigationControllerDidCancel: method.

Has anyone else experienced this issue?

Here is the code snippet of my subclass ABPeoplePickerNavigationController :

 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier]; } - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { ...do stuff... return NO; } - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { return YES; } - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { [self dismissViewControllerAnimated:self.shouldAnimateDismiss completion:NULL]; } 
+6
source share
4 answers

Where do you point peoplePickerDelegate ?

In iOS 8, if you specify peoplePickerDelegate in viewDidLoad , you will encounter a curious behavior that you describe (cancel the delegate, didSelect... and shouldContinue... no). If you specify peoplePickerDelegate immediately after init (or during), it works fine.

This will be a feature of iOS 8. "I will write a bug report.

+6
source

above two delegate methods are deprecated in ios 8.0, use use methods last two for getting your desire result

the two delegate methods above are deprecated in iOS 8.0, use the last two methods to get the result of your desire

this link to the apple developer link gives you more information about

ABPeoplePickerNavigationControllerDelegate

+2
source

Nothing will happen when I selected a contact in iOS8.

I found that besides

 if ([picker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)]) { picker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@" emailAddresses.@count = 1"]; } 

I also needed

 if ([picker respondsToSelector:@selector(setPredicateForEnablingPerson:)]) { picker.predicateForEnablingPerson = [NSPredicate predicateWithFormat:@" emailAddresses.@count > 0"]; } 

Source https://developer.apple.com/library/prerelease/ios/samplecode/PeoplePicker/Listings/PeoplePicker_AAPL_8or7_EmailPickerViewController_m.html

0
source

If you just want to get the person’s name, you can do this:

 -(IBAction)btnGetContact{ ABPeoplePickerNavigationController *personPicker = [ABPeoplePickerNavigationController new]; personPicker.peoplePickerDelegate = self; [self presentViewController:personPicker animated:YES completion:nil]; } -(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ NSString *firstName; NSString *middleName; NSString *lastName; UIImage *retrievedImage; // get the first name firstName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); //get the middle name middleName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty); // get the last name lastName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); // get personPicture if (person != nil && ABPersonHasImageData(person)) { retrievedImage = [UIImage imageWithData:(__bridge_transfer NSData*)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)]; } else { retrievedImage = nil; } } 

But if you want to go to the details of the person to get the numbers of people, you should use BOOL instead of void for peoplePickerNavigationController and pass YES , as shown below:

 -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ return YES; } -(void) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{ ABMutableMultiValueRef phoneno = ABRecordCopyValue(person, kABPersonPhoneProperty); CFStringRef phone = ABMultiValueCopyValueAtIndex(phoneno, identifier); _mPhone.text = (__bridge NSString *)phone; [self dismissViewControllerAnimated:NO completion:^(){}]; } 

Also remember to import AddressBook.framework and AddressBookUI.framework into your project and ABPeoplePickerNavigationControllerDelegate ,

 #import <AddressBook/AddressBook.h> #import <AddressBookUI/AddressBookUI.h> 

to the header file.

0
source

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


All Articles