Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ABAddressBook ABSourceName

How can I get the name of an ABAddressBook source to display it? (I know the enums kABSourceTypeLocal, kABSourceTypeExchange, ... )

I don't mean the source-type-name you get with ABRecordCopyValue(source,ABSourceNameProperty), but the real name which is shown in Apple's Contacts-App as a table section, for example: "Exchange Google" or "iCloud"

like image 795
iPhoneNerd Avatar asked May 08 '12 08:05

iPhoneNerd


1 Answers

If you check out the ABSource Reference, you can see that they have a property called kABSourceNameProperty that contains "the name of the source". Here's how you would get all the source names:

NSMutableArray *sourceNames = [[NSMutableArray alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef sourcesArray = ABAddressBookCopyArrayOfAllSources(addressBook);

for (CFIndex i = 0; i < CFArrayGetCount(sourcesArray); i++) {
    ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(sourcesArray, i);
    CFStringRef sourceName = (CFStringRef)ABRecordCopyValue(ABRecordGetRecordID(source, kABSourceNameProperty);

    if(sourceName){
        [sourceNames addObject: (__bridge_transfer NSString *)sourceName];
    }
}

CFRelease(sourcesArray);
CFRelease(addressBook);

Hope this helps!

like image 74
pasawaya Avatar answered Nov 17 '22 10:11

pasawaya