我使用下面的代码尝试在addressBook中建立一个新的联系人,由于某种原因,当我到达ABAddressBookAddRecord时,didset返回false,我无法弄清楚原因。有没有忘记打电话的功能,因为我觉得这应该有效?
ABRecordRef record = ABPersonCreate();
CFErrorRef err = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, &err);
bool didset;
didset = ABRecordSetValue(record, kABPersonFirstNameProperty, CFSTR("test"), &err);
didset = ABRecordSetValue(record, kABPersonLastNameProperty, CFSTR("monkey"), &err);
didset = ABRecordSetValue(record, kABPersonPhoneProperty, CFSTR("123-123-1234"), &err);
didset = ABAddressBookAddRecord(addressBook, record, &err);
if (ABAddressBookHasUnsavedChanges(addressBook))
{
didset = ABAddressBookSave(addressBook, &err);
}