将电话号码添加到ABPerson

时间:2014-04-20 22:02:00

标签: ios objective-c abaddressbook abperson

我尝试为每个值添加一个字符串,但我得到错误,有人可以演示如何将数字添加到ABPerson这是我的尝试:

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 个答案:

答案 0 :(得分:2)

要设置记录的电话号码,您需要使用以下代码:

ABMutableMultiValueRef phoneNumbers = ABMultiValueCreateMutable(kABMultiStringPropertyType);

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

ABRecordSetValue(pet, kABPersonPhoneProperty, phoneNumbers, nil);

要了解详情,请查看my tutorial.

答案 1 :(得分:-1)

ABRecord中的数字是一个多值属性,您无法像这样设置。

看看这个link