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; } }