Add phone numbers to ABPerson

312 views Asked by At

I try to put in a string for each of the values and I get errors, can someone demonstrate how to add numbers to an ABPerson here is my attempt:

if (_cellNumber) {
    ABRecordSetValue(person, kABPersonPhoneMobileLabel, (__bridge CFTypeRef)(_lastName), NULL);
}

if (_workNumber) {
    ABRecordSetValue(person, kABWorkLabel, (__bridge CFTypeRef)(_lastName), NULL);
}

if (_defaultNumber) {
    ABRecordSetValue(person, kABPersonPhoneMainLabel, (__bridge CFTypeRef)(_lastName), NULL);
}
2

There are 2 answers

0
Christian On

The numbers in ABRecord are a multi-value property that you can not set like that.

Have a look at this link

0
erdekhayser On

To set the record's phone numbers, you need to use the following code:

ABMutableMultiValueRef phoneNumbers = ABMultiValueCreateMutable(kABMultiStringPropertyType);

ABMultiValueAddValueAndLabel(phoneNumbers, (__bridge CFStringRef)phoneNumberString, kABPersonPhoneMainLabel, NULL);

ABRecordSetValue(pet, kABPersonPhoneProperty, phoneNumbers, nil);

To read more about this, check out my tutorial.