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"
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With