Friday, April 27, 2012

How to append phone number to an existing contact.


    //We need to create a mutable copy of ABMultiValueRef with property kABPersonPhoneProperty
    
    ABMultiValueRef Phones = ABRecordCopyValue(contact, kABPersonPhoneProperty);
    ABMutableMultiValueRef Phone = ABMultiValueCreateMutableCopy(Phones);
    ABMultiValueAddValueAndLabel(Phone,@"413-675-1234", kABOtherLabel, NULL);
    ABMultiValueAddValueAndLabel(Phone@"413-675-1235", kABOtherLabel, NULL); 
    ABRecordSetValue(contact, kABPersonPhonePropertyPhone,nil);
    CFRelease(Phone);

    //This will add 2 numbers with others title under phone section of contact.
    //You can use other label too like following kABWorkLabel or kABPersonPhoneMobileLabel 

    ABMultiValueAddValueAndLabel(Phone,@"413-675-1234"kABPersonPhoneMobileLabelNULL);
    ABMultiValueAddValueAndLabel(Phone@"413-675-1235"kABWorkLabelNULL); 


    //Dont forget to save your addressbook after that.

    ABAddressBookSave(addressbook, &error);
    if (error != NULL
    {
        NSLog(@"failed");

    }
      NSLog(@"success.");

Note: If you don't make a  mutable copy, you will get following error for trying add  phone number to ABMultiValueRef instead of ABMutableMultiValueRef. As you created ABMultiValueRef by copying from ABRecordRef using method ABRecordCopyValue.
Assertion failed: (((ABCMultiValue *)multiValue)->flags.isMutable), function ABMultiValueAddValueAndLabel





2 comments:

  1. Nice blogs
    thank for sharing information.
    Durga MaaTo Activate just dial*500*73# for Mai Durga and for Deactivation dial*500*74#
    Charges
    Rs. 30/30days

    ReplyDelete
  2. Thanks for sharing these. It’s always useful to get pointers to the good blogs out there.
    Phone Appending service offered by Parana Impact will help your organization fill in the blanks in your databases.

    ReplyDelete