ABMultiValueCopyLabelAtIndex returns null, but the label is visible in the address book

I am trying to read the label of a specific instant messaging service in an address book. In this case, I am testing with the Facebook Messenger service on my phone. The contact is associated with contacts, but with only one recorded instant messaging service.

I tried to find information on how it works ABMultiValueCopyLabelAtIndex

, but all I found is that it "can return null". If there is no visible label in the address book, yes, I understand why it will return null. In this case, however, there is a shortcut and it reads "Facebook Messenger" in human view. Why?

- (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

[...]
}

      

+3


source to share





All Articles