I am trying to update the contents of an existing contact in the address book through my application, but without using the user interface. The scenario is as follows:
1 The user enters the number and name 2 The application checks whether this name is in the contact list 3 if he then checks whether the number is one of the contacts for this name 4 If it is not added to this name
I was able to follow steps 1-3, but I could not find a way to do 4. Can someone help?
Below if my code looks like
... CFIndex lTotalContactsCount = ABAddressBookGetPersonCount(lAddressBook); NSArray *people = (NSArray *)ABAddressBookCopyArrayOfAllPeople(lAddressBook ); for (CFIndex i = 0; i < lTotalContactsCount; i++) { ABRecordRef lRef = (ABRecordRef)[people objectAtIndex:i]; ... // if names match { ABMutableMultiValueRef lPhoneNumbers = ABRecordCopyValue(lRef, kABPersonPhoneProperty); CFIndex lContactPhoneNumberCount = ABMultiValueGetCount(lPhoneNumbers); ABRecordID contactID = ABRecordGetRecordID(lRef); ... // if numbers dont match { // THIS BIT IS NOT WOKRING CFErrorRef error = NULL; ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); ABMultiValueAddValueAndLabel(multiPhone, number, (CFStringRef)@"Duplicate", NULL); // ABRecordSetValue(newPerson, kABPersonFirstNameProperty, name, &error); //add the number to the contact ABRecordSetValue(lRef, kABPersonPhoneProperty, multiPhone,nil); // ABAddressBookAddRecord(lAddressBook, lRef, &error); ABAddressBookSave(lAddressBook, &error); } if( firstName ) CFRelease(firstName); if( lastName ) CFRelease(lastName); if( lPhoneNumbers ) CFRelease(lPhoneNumbers); // no need to search other entries if(numberExists) break; }
source share