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

320 views Asked by At

I'm trying to read the label of a particular instant message service in the address book. In this case I'm testing with the Facebook Messenger service, on my phone. The contact has linked contacts, but only one recorded instant message service.

I tried to find info on how ABMultiValueCopyLabelAtIndex works, but all I found was that it "may return null". If there's no visible label in the address book then yeah, I understand why it would return null. In this case however there is a label, and it reads "Facebook Messenger" in the person view. I still get null, 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

[...]
}
0

There are 0 answers