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
ios abaddressbook abmultivalue


source to share


No one has answered this question yet

Check out similar questions:

534
How to tell if a UIViewController view is visible
6
iPhone: Address Book is sometimes erased
4
User information in the address book on iOS
4
Iterating through iPhone address book calling sql db corrupt address book
2
access to kABPersonURLProperty from the address book
2
FaceBook Connect. Login to the system
1
I get a contact with multiple addresses, but I only want the home address
0
length of the NSString object has a value that is incorrect
0
ABPersonViewController does not open in editable mode
0
How to determine which contact is imported from Facebook to iOS



All Articles
Loading...
X
Show
Funny
Dev
Pics