开发者

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, phoneNumberMul开发者_JS百科tiValue, nil); 

}

any ideas?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜