IPhone: How do you get the names of all the address books on the iPhone?

Some users have multiple address books in their iPhone contacts as a result of various synchronization connections that they made using, for example, Exchange Servers.

How can I get all these different address books? I would be interested to get the names under which these different address books are stored and access to their contact information.

Thank!

+3
source share
2 answers
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef sourcesArray = ABAddressBookCopyArrayOfAllSources(addressBook);
for (CFIndex i = 0; i < CFArrayGetCount(sourcesArray); i++) {
    ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(sourcesArray, i);
    ABRecordID sourceID = ABRecordGetRecordID(source);
    CFNumberRef sourceType = (CFNumberRef)ABRecordCopyValue(source, kABSourceTypeProperty);
    CFStringRef sourceName = (CFStringRef)ABRecordCopyValue(source, kABSourceNameProperty);
    NSLog(@"source id=%d type=%d name=%@", sourceID, [(NSNumber *)sourceType intValue], sourceName);
    CFRelease(sourceType);
    if (sourceName != NULL) CFRelease(sourceName); // some source names are NULL
}
CFRelease(sourcesArray);
CFRelease(addressBook);

Note that with iOS 4, not all sources return a name. You can specify your own names by type.

Use ABAddressBookCopyArrayOfAllPeopleInSource(addressBook, source)to get records in the source.

+6
source

iOS, C, . ABAddressBook iOS.

. , ABAddressBookCopyArrayOfAllGroups, ABGroup.

-1

Source: https://habr.com/ru/post/1785209/


All Articles