iphoneiosabpersonviewcontrollerabrecordref

Setting person properties


Working on someone else's code. I am really confused about whats exactly happening in this code.

ABAddressBookRef addressBook = ABAddressBookCreate(); 
ABRecordRef persons = ABAddressBookGetPersonWithRecordID(addressBook, x);
CFErrorRef *error=NULL;
ABAddressBookRemoveRecord(addressBook, persons, error);
ABAddressBookSave(addressBook, error);

ABRecordRef persons = ABPersonCreate(); 

ABRecordSetValue(persons, kABPersonFirstNameProperty, firstName , nil);

What should be done is that, a ABRecordRef person should be created. His properties should be set and his record/details should be displayed. He should never be saved in the address book. Is this the way to do it. Need help.

Edit: Apart from setting properties to person, the following code is added to push the view controller to view the person.

MyContactDetailViewcontroller *personContactDetail = [[MyContactDetailViewcontroller alloc] init];
personContactDetail.displayedPerson = persons; 
personContactDetail.passedSelectedContactData = selectedContactsOnlyData;
[self.navigationController pushViewController:personContactDetail animated:YES];
[personContactDetail release];

MyContactDetailViewcontroller subclass ABPersonViewController. Or is it more apt to use ABUnknownPersonViewController.

Do you find any cases where the contacts could be duplicated in address book


Solution

  • This is exactly what is happening here.. I will explain..

    ABAddressBookCreate creates a new address book from data from the addressbook database, so any changes you make to ABAddressBookRef will only be saved to actual addressbook database once you call ABAddressBookSave(). so what it is doing is getting the reference for the person with recordid- x. Than you are creating a new person entry using

    ABRecordRef persons = ABPersonCreate(); 
    

    and than you are setting its value, but this is available to this particular object and not stored in the database unless you call... ABAddressBookSave()

    hoping this helps you... :)