I am using an ABNewPersonViewController to create a person. Everything works fine so far. I do set multivalue properties as well as single values. After tapping “Add” the contact can be found in the adressbook.
But there is a problem when editing this contact. After adding the contact to the adressbook, I save the addressbookID, so that I am able to identfiy if the contact is still saved in the AB.
So If the user wants to export a contact again, I do not create a new ABPersonRecordRef, but using the existing one identified by the id I have saved before:
ABRecordID recordId = [aContact.addressBookRecordId intValue];
ABRecordRef personRecord = nil;
if(recordId != 0) {
personRecord = ABAddressBookGetPersonWithRecordID(addressBook, recordId);
if(personRecord) {
return personRecord;
} else {
personRecord = ABPersonCreate();
}
} else {
personRecord = ABPersonCreate();
}
//set properties etc.
The problem now is, that this just works the first time. If the user displays the person a second time in the ABNewPersonViewController and taps on Cancel, the record will be deleted in the adress book. Although it was previously saved fine.
I tried using an ABUnknownPersonViewController, but the problem is that it seems that the attributes det on the recordRef are not displayed exactly like in the ABNewPersonViewController.
Any suggestions?
This will be of use to you:
Can ABNewPersonViewController be used to edit existing records?
It covers a tutorial with your exact problem.