我正在尝试读取通讯簿中特定即时消息服务的标签。在这种情况下,我正在手机上使用 Facebook Messenger 服务进行测试。该联系人已链接联系人,但只有一个记录的即时消息服务。
我试图找到有关如何ABMultiValueCopyLabelAtIndex
工作的信息,但我发现它“可能返回 null”。如果通讯簿中没有可见的标签,那么是的,我明白为什么它会返回 null。但是在这种情况下,有一个标签,它在人员视图中显示为“Facebook Messenger”。我仍然为空,为什么?
- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)personRecord property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
// all IM services:
ABMultiValueRef instantMessageProperty = ABRecordCopyValue(personRecord, property);
// one particular IM service:
CFDictionaryRef instantMessageDict = ABMultiValueCopyValueAtIndex(instantMessageProperty, ABMultiValueGetIndexForIdentifier(instantMessageProperty, identifierForValue));
// its name:
NSString *serviceName = (__bridge NSString*)CFDictionaryGetValue(instantMessageDict, kABPersonInstantMessageServiceKey);
// its label:
NSString *serviceLabel = (__bridge_transfer NSString*)ABMultiValueCopyLabelAtIndex(instantMessageProperty, ABMultiValueGetIndexForIdentifier(instantMessageProperty, identifierForValue));
NSLog(serviceName); // logs "Facebook", so things seem to work
NSLog(serviceLabel); // logs nothing, and I confirmed that serviceLabel == nil
[...]
}