Code:
ABAddressBookRef book = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(book);
ABRecordRef ref = CFArrayGetValueAtIndex(people, 1);
ABMultiValueRef mutablePhones =(NSString *)ABRecordCopyValue(ref,kABPersonPhoneProperty);
ABRecordRef current = ABPersonCreate();
NSString *phoneNumber, *phoneNumberLabel;
for (CFIndex i = 0; i < ABMultiValueGetCount(mutablePhones); i++)
{
phoneNumberLabel = (NSString*)ABMultiValueCopyLabelAtIndex(mutablePho nes, i);
// phone number of this record! --old---
phoneNumber = ABMultiValueCopyValueAtIndex(mutablePhones, i);
if ( YES == [ phoneNumberLabel isEqualToString: @"_$!<Mobile>!$_"] )
{
NSString *mainPhone = @"111111111111111111111";
if(ABMultiValueReplaceValueAtIndex (mutablePhones, mainPhone,i))
{
ABRecordSetValue(current, kABPersonPhoneProperty, mutablePhones, NULL);
// phone number of this record! --new---
NSString *phoneNumber2 = ABMultiValueCopyValueAtIndex(mutablePhones, i);
NSLog(@"that phone number has been updated to %@.", mainPhone);
}
}
}
ABAddressBookSave(book, nil);
contact's mobile phone number was not be changed! why?