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 ?

4

1 回答 1

0

首先:ABAddressBookCreate已被弃用,并且在 iOS 6 下无法使用(它总是返回 NULL)。而是使用ABAddressBookCreateWithOptions(文档:http: //developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html)。

之后,您需要保存地址簿以使更改持续存在,通过ABAddressBookSave使用您的地址簿调用来做到这一点。

于 2013-04-18T11:33:31.700 回答