Reputation: 10159
I am trying to replicate the iPhone's default behavior for adding a phone number to an existing contact. To clarify, I am talking about the UI, not programmatically.
My first attempt was to present an ABPeoplePickerNavigationController
and when the user selects a person, present a ABNewPersonViewController
with the selected person. The problem with this method is that if the user hits the cancel button, the contact is deleted from the address book.
Upvotes: 3
Views: 1344
Reputation: 9810
You should be implementing the peoplePickerNavigationControllerDidCancel:
delegate method (as it is required), and you can save the person back if you need.
A (probably better) way to handle it, would be to copy the address book, present a ABPeoplePickerNavigationController
with the copy, and then when the UI is finished, you will know if you should keep the original (if someone got deleted on accident ?) or replace it with the copy with the added information. Hope this helps! Also, take a look at Apple's QuickContacts Sample Code here!
Edit for how to copy an address book's people array:
// Fetch the address book
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *copy = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook)
Another Edit: A good place to start in the developer guides for this is the ABAddressBook docs here
Upvotes: 3