【问题标题】:How to update: (COCOA/OSX) ABPerson / ABMultiValue (phonenumbers)?如何更新:(COCOA/OSX)一个人/一个多值(电话号码)?
【发布时间】:2011-01-11 22:01:33
【问题描述】:
II 试图改变 ABPerson / ABMultiValue 的值(电话号码)。
无论如何要更新这些?
ABAddressBook *ab = [ABAddressBook sharedAddressBook];
NSArray *persons = [ab people];
int j=[persons count];
for (int i=0; i<j; i++) {
ABPerson *person = [persons objectAtIndex:i];
ABMultiValue *phonenumbers = [person valueForProperty:kABPhoneProperty];
// update here *phonenumbers
}
谢谢!
【问题讨论】:
标签:
cocoa
macos
addressbook
abaddressbook
abmultivalue
【解决方案1】:
尝试调用:
ABMultiValueRef phoneNumbers = ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumbers, value, label, null);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumbers, NULL);
添加以下之一:ABMultiValueAddValueAndLabel(phoneNumbers, value, label, null) 用于您要添加的每个值。
【讨论】:
-
不要使用ABMultiValueCreateMutable(kABPersonPhoneProperty),而是使用ABMultiValueCreateMutable(kABMultiStringPropertyType),否则你会在控制台上打印“Can't return type callbacks for 3”(可能以后会发生不好的事情)。 source