1

Hello everyone I am trying to update a contact's phone using the following code

ABAddressBookRef addressBook = ABAddressBookCreate();
    CFErrorRef error = nil;
    ABMutableMultiValueRef phoneMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);
    bool didAddphone = ABMultiValueAddValueAndLabel(phoneMultiValue, (CFTypeRef)(_homePhoneText.text), kABHomeLabel, NULL);

if(didAddphone){
        ABRecordSetValue(ABAddressBookGetPersonWithRecordID(addressBook, [_ID integerValue]),
                         kABPersonPhoneProperty,
                         phoneMultiValue,
                         nil);
    } else {
        NSLog(@"Error adding email: %@", error);
        error = nil;
    }

But its not working. Any help ?

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
veereev
  • 2,650
  • 4
  • 27
  • 40

1 Answers1

0

First off: ABAddressBookCreate is deprecated and will not work under iOS 6 (it always returns NULL). Instead use ABAddressBookCreateWithOptions (documentation: http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html ).

After that, you need to save the address book to make the changes stick around, do that by calling ABAddressBookSave with your address book.

Hampus Nilsson
  • 6,692
  • 1
  • 25
  • 29
  • Hello ok i am now using : CFErrorRef error = nil; ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error); Can you tell me how to add ABAddressBookSave? – veereev Apr 18 '13 at 11:53
  • kool great it works!! ABAddressBookSave(addressBook, &error); – veereev Apr 18 '13 at 11:55