user1357350
user1357350

Reputation: 777

Count total number of contacts from address book - iOS

How can I count the total number of contacts from the address book?

Upvotes: 2

Views: 1925

Answers (3)

tilo
tilo

Reputation: 14169

Try this

#import <AddressBook/AddressBook.h>
// ...

- (int)contactsCount {    
    ABAddressBookRef addressBook = ABAddressBookCreate( );
    CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
    CFRelease( addressBook );
    return (int)nPeople;
}

Upvotes: 6

Rok Jarc
Rok Jarc

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

lex87
lex87

Reputation: 1326

NSArray *people = [book people];
int count = [[book people] count];

Upvotes: -1

Related Questions