Reputation: 37581
I'm adding a contact to the address book, so far it just contains the name and phone number.
The contact appears in the address book when I go to view it but the phone number isn't present.
ABAddressBookRef adbk = ABAddressBookCreate();
ABRecordRef contact = ABPersonCreate();
CFErrorRef error = nil;
BOOL success = ABRecordSetValue(contact, kABPersonFirstNameProperty, @"f name", &error);
ABMutableMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
success = ABMultiValueAddValueAndLabel(phone, @"123456789",kABPersonPhoneMainLabel, nil);
CFRelease(phone);
success = ABAddressBookAddRecord(adbk, contact, &error);
success = ABAddressBookSave(adbk, &error);
CFRelease(contact);
CFRelease(adbk);
Tried replacing kABPersonPhoneMainLabel with for example kABPersonPhoneMobileLabel but it makes no difference. Why is the name appearing but not the phone number?
Every function returns YES.
Upvotes: 0
Views: 255
Reputation: 22701
Looks like your forgetting to call ABRecordSetValue with the phone number. See snippet below.
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, @"1-555-555-5555", kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, @"1-123-456-7890", kABPersonPhoneMobileLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, @"1-987-654-3210", kABOtherLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
Upvotes: 1