怎麼樣獲取保存在通訊錄中的所有群組名字?相關代碼:
NSMutableArray *list = [NSMutableArray array];
ABAddressBookRef myAddressBook = ABAddressBookCreate();
CFArrayRef allSources = ABAddressBookCopyArrayOfAllGroups(myAddressBook);
list = [NSMutableArray arrayWithArray: (__bridge NSArray*) allSources];
NSLog(@"GROUPS %@",[list objectAtIndex:0]);
謝謝
使用ABRecordCopyCompositeName()
功能:
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
if (addressBook != NULL) {
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted) {
CFArrayRef allGroups = ABAddressBookCopyArrayOfAllGroups(addressBook);
if (allGroups != NULL) {
NSMutableArray *names = [NSMutableArray array];
for (int i = 0; i < CFArrayGetCount(allGroups); i++) {
ABRecordRef group = CFArrayGetValueAtIndex(allGroups, i);
CFStringRef name = ABRecordCopyCompositeName(group);
[names addObject:(__bridge NSString *)name];
CFRelease(name);
}
NSLog(@"names = %@", names);
CFRelease(allGroups);
}
}
CFRelease(addressBook);
});
}