Application error when using PeoplePicker, but not in the same form

Update 2, I hope this helps someone, there are solutions at the following link: https://discussions.apple.com/thread/5498630?start=0&tstart=0 , obviously this is an iOS error, and this is working on the work. I can create a new sharedPicker, but I canโ€™t get anything from it or reject it, Iโ€™m not sure how to format beyond what is provided by the link Any help on this is very welcome.

So now my question is how to take the following code and actually create the code for peoplePickerNavigationControllerDidCancel: and peoplePickerNavigationController: shouldContinueAfterSelectingPerson: Thank you. I left most of my original message in case anyone has a vague problem.

// Convoluted workaround for the iPhone 4S crash + (ABPeoplePickerNavigationController *)sharedPeoplePicker { static ABPeoplePickerNavigationController *_sharedPicker = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _sharedPicker = [[ABPeoplePickerNavigationController alloc] init]; }); return _sharedPicker; } // then later on, use [YourController sharedPeoplePicker].delegate = self; // etc. 

My current code is:

 - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { [self displayPerson:person]; [self.navigationController dismissViewControllerAnimated:YES completion:nil]; return NO; } - (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker { //[self dismissViewControllerAnimated:YES completion:nil]; [self.navigationController dismissViewControllerAnimated:YES completion:nil]; } - (IBAction)pick1:(id)sender { ABPeoplePickerNavigationController *picker1 =[[ABPeoplePickerNavigationController alloc] init]; picker1.peoplePickerDelegate = self; [self presentViewController:picker1 animated:YES completion:nil]; x=1; } 

Update 1, this application crashes on iPhone 4/4, but works in the simulator and iPhone5, if that means anything. I think that only they have enough strength to overcome the leaks that I created.

I have an iOS application with a view controller in which the user can select contacts for the application using ABPeoplePickerNavigationController or enter numbers manually. If the numbers are entered manually, there is no problem. If the user opens and:

  • Selects a new contact from the address book

  • Updates a contact from the address book for use in the application

  • Opens and cancels the address book (all without saving the action)

Then I cannot go to one specific view in my application without crashing. I am at a loss why I cannot go to this view controller or why it causes a crash.

I use 5 different collectors, one for each contact that I want to add and potentially save. I save as NSUserDefaults , but as I said, the crash persists even if the selection is never saved. I can go to all the views in the application from the navigation in the sidebar without any incidents, the only thing that differs from the view with which I fail is that it is presented from one of the main view controllers, and not on the side panel .

I appreciate any help or thoughts. This was the first application I wrote, and I'm trying to update it and fail. I want it to be functional again so that I can go back and reorganize it.

My implementation:

  - (IBAction)pick1:(id)sender { ABPeoplePickerNavigationController *picker1 = [[ABPeoplePickerNavigationController alloc] init]; picker1.peoplePickerDelegate = self; [self presentViewController:picker1 animated:YES completion:nil]; x = 1; } - (IBAction)pick2:(id)sender { ABPeoplePickerNavigationController *picker2 = [[ABPeoplePickerNavigationController alloc] init]; picker2.peoplePickerDelegate = self; [self presentViewController:picker2 animated:YES completion:nil]; x=2; } - (IBAction)pick3:(id)sender { ABPeoplePickerNavigationController *picker3 = [[ABPeoplePickerNavigationController alloc] init]; picker3.peoplePickerDelegate = self; [self presentViewController:picker3 animated:YES completion:nil]; x=3; } - (IBAction)pick4:(id)sender { ABPeoplePickerNavigationController *picker4 = [[ABPeoplePickerNavigationController alloc] init]; picker4.peoplePickerDelegate = self; [self presentViewController:picker4 animated:YES completion:nil]; x=4; } - (IBAction)pick5:(id)sender { ABPeoplePickerNavigationController *picker5 = [[ABPeoplePickerNavigationController alloc] init]; picker5.peoplePickerDelegate = self; [self presentViewController:picker5 animated:YES completion:nil]; x=5; } - (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker { [self dismissViewControllerAnimated:YES completion:nil]; } - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { [self displayPerson:person]; [self.navigationController dismissViewControllerAnimated:YES completion:nil]; return NO; } - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { return NO; } - (void)displayPerson:(ABRecordRef)person { NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty); NSString* phone = nil; ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty); if (ABMultiValueGetCount(phoneNumbers) > 0) { phone = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, 0); } else { phone = @"[None]"; } if (x==1){ firstName1.text = name; contact1.text = phone; } if (x==2){ firstName2.text = name; contact2.text = phone; } if (x==3){ firstName3.text = name; contact3.text = phone; } if (x==4){ firstName4.text = name; contact4.text = phone; } if (x==5){ firstName5.text = name; contact5.text = phone; } } 
+6
ios uiviewcontroller abpeoplepickerview
source share
3 answers

Sorry to answer my own question, but another work around this that requires minor changes is to use CF Retain to fix the above release. I saved man and people, and everything was decided. Thanks to everyone who tried to help me solve this problem.

 - (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker { [self.navigationController dismissViewControllerAnimated:YES completion:nil]; CFRetain((__bridge CFTypeRef)(peoplePicker)); } - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { [self displayPerson:person]; [self.navigationController dismissViewControllerAnimated:YES completion:nil]; CFRetain(person); CFRetain((__bridge CFTypeRef)(peoplePicker)); return NO; } 
+3
source share

Thanks for working on this issue. Your method # 2 really works !!! I have a similar situation discussed at https://discussions.apple.com/thread/5498630?start=0&tstart=0 : MKMapView is placed IB in the storyboard, with no code except IBOutlet. I represent ABPeoplePickerController and then just cancel it by firing and leaving this view using navigation. Then go back and get a memory problem: the barStyle method of the zombie UINavigationBar called at the address of the rejected ABPeoplePickerController. This situation occurred only on iOS 7 (iPad 3rd ten and iPhone 4S), but the code works fine on iOS 6 (iPhone 3GS) and only with a combination with MKMapView. I am testing WebView instead of MapView and everything is working fine. I think this is a real mistake in iOS 7. Sincerely, Alexey

+1
source share

Well, there is a slightly simpler solution. The actual problem is using ABPeoplePickerNavigationController as a singleton object, setting its delegate to the view controller, and then rejecting the view controller. So, in my case, the solution that worked was this:

 - (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker { peoplePicker.peoplePickerDelegate = nil; // clear delegate prior to dismissing self [self.navigationController dismissViewControllerAnimated:YES completion:nil]; } - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { [self displayPerson:person]; peoplePicker.peoplePickerDelegate = nil; // clear delegate prior to dismissing self [self.navigationController dismissViewControllerAnimated:YES completion:nil]; return NO; } 
0
source share

All Articles