I get a success message, contact is successfully updated but in contact application not display updated name.
I have call below method for updating my contact name.
-(void)updateAddressBook
{
CFErrorRef *error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL,error);
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
CFArrayRef sortedPeople =ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName);
CFIndex number = CFArrayGetCount(sortedPeople);
NSString *firstName;
NSString *phoneNumber ;
for( int i=0;i<number;i++)
{
ABRecordRef person = CFArrayGetValueAtIndex(sortedPeople, i);
firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
phoneNumber = (__bridge NSString *) ABMultiValueCopyValueAtIndex(phones, 0);
ABRecordID recordID1 = ABRecordGetRecordID(person);
NSLog(@"%d", recordID1);
ABRecordRef record = ABAddressBookGetPersonWithRecordID(addressBook, recordID1);
NSNumber *recordId = [NSNumber numberWithInteger:ABRecordGetRecordID(record)];
NSLog(@"recordId:- %d",[recordId intValue]);
bool didSet;
//update First name
didSet = ABRecordSetValue(record, kABPersonFirstNameProperty, (__bridge CFTypeRef)([NSString stringWithFormat:@"Person Name"]) , nil);
if (didSet) {
NSLog(@"contact is successfully updated");
}else{
NSLog(@"error");
}
CFStringRef firstName;
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSLog(@"%@",firstName);
ABAddressBookSave(addressBook, error)
}
}