phil swenson
phil swenson

Reputation: 8904

Adding phone number to iphone contact - but NOT replacing!

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?

Upvotes: 1

Views: 1848

Answers (1)

Ken Aspeslagh
Ken Aspeslagh

Reputation: 11594

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);
}

Upvotes: 2

Related Questions