tags:

views:

114

answers:

1

I am trying to replicate the behavior that the iphone that happens when you tap and hold on a phone number link in a text field you get a menu "create new contact" and "add to existing contact". I have this working except for one thing. In the "add to existing" apple implementation if there is already a home contact, it just adds another one. It doesn't REPLACE it. So you can have multiple home phone numbers.

In my implementation it replaces it. So how do I do a not-destructive phone number add?

Here is my code:

+(void)updatePhone:(ABRecordRef)person phone:(NSString*)phone{
ABMutableMultiValueRef phoneNumberMultiValue =  ABMultiValueCreateMutable(kABPersonPhoneProperty);  
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, phone,  kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);

}

any ideas?

A: 

Did you try querying for the existing phone numbers, and then adding your new one?

Something like this (code not tested):

+(void)updatePhone:(ABRecordRef)person phone:(NSString*)phone{
ABMutableMultiValueRef phoneNumberMultiValue =  ABMultiValueCreateMutableCopy (ABRecordCopyValue(person, kABPersonPhoneProperty));
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, phone,  kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
}
Ken Aspeslagh
here is my exact code. works whether there are phone #s previously entered or not:+(void)updatePhone:(ABRecordRef)person phone:(NSString*)phone{ ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutableCopy (ABRecordCopyValue(person, kABPersonPhoneProperty)); ABMultiValueAddValueAndLabel(multiPhone, phone, kABPersonPhoneMobileLabel, NULL); ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone,nil); CFRelease(multiPhone);}
phil swenson