Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jinlianhai

macrumors newbie
Original poster
Jan 5, 2009
1
0
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?
 
ABMultiValueCreateMutableCopy

Hi,

you need to do a mutableCopy before.

ABAddressBookRef book = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(book);
ABRecordRef ref = CFArrayGetValueAtIndex(people, 1);
ABMultiValueRef mutablePhones =(NSString *)ABMultiValueCreateMutableCopy(ABRecordCopyValue(ref,kABPersonPhoneProperty));
ABRecordRef current = ABPersonCreate();
NSString *phoneNumber, *phoneNumberLabel;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.