Reputation: 777
How can I count the total number of contacts from the address book?
Upvotes: 2
Views: 1925
Reputation: 14169
Try this
#import <AddressBook/AddressBook.h>
// ...
- (int)contactsCount {
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
CFRelease( addressBook );
return (int)nPeople;
}
Upvotes: 6
Reputation: 18865
You could try using Erica Sadun's ABContactHelper.
At least as a starting point.
In ABContactsHelper.h there are declarations:
+ (int) contactsCount;
+ (int) contactsWithImageCount;
+ (int) contactsWithoutImageCount;
+ (int) numberOfGroups;
I think it's a little outdated so you might have to tweak the code a little.
Upvotes: 0
Reputation: 1326
NSArray *people = [book people];
int count = [[book people] count];
Upvotes: -1