I am trying to get the total count for the phone numbers listed in the AddressBook, in all groups as a whole.
I can successfully retrieve Person count and Group count, just not the total number of Phone Numbers.
ABAddressBookRef m_addressbook = ABAddressBookCreate();
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
CFIndex nGroups = ABAddressBookGetGroupCount(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
Should return the count for everyone in the address book.
Try this:
ABAddressBookRef addressbook = ABAddressBookCreate();
int nPeople = ABAddressBookGetPersonCount(addressbook);
printf("%d",nPeople);
Related
I want to select multiple contacts from the iPhone address book and save selected contacts in my app. then I have to retrieve record of that selected contacts.
check this demo
1) multicontactsselector
2) knmultiitemselector
3) tkcontactsmultipicker
Try this
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
for ( int i = 0; i < nPeople; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
...
}
Is it possible to know the number of entries stored inside the iOS address book programmatically?
Use ABAddressBookGetPersonCount to count total contacts, Like :-
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
for ( int i = 0; i < nPeople; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
...
}
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex peopleCount = CFArrayGetCount(people);
CFArrayRef groups = ABAddressBookCopyArrayOfAllGroups(addressBook);
CFIndex groupsCount = CFArrayGetCount(groups);
For more information please see the Address Book Programming Guide for iOS.
I Want to get the contacts on the device without using ABPeoplePickerNavigationController, it is possible in objective-c?
Yes, it's possible. Below there's a simple snippet of code that do the work:
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeopleRef = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, nil, kABPersonSortByFirstName);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for( int i = 0 ; i < nPeople ; i++ ) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeopleRef, i );
CFStringRef tmpStringRef = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSLog(#"FirstName: %#", (NSString *)tmpStringRef);
CFRelease(tmpStringRef);
}
//clean up memory
CFRelease(allPeopleRef);
CFRelease(addressBook);
For more details, please refer to the Apple Developer Documentation here.
It is. Please refer to the AddresBook programming guide. Direct interaction section.
In my app i am getting contacts like this..
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for( int i=0;i< nPeople;i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
.....
and so on
}
can anyone suggest me how to get the group for nPeople.
Check the following documentation
http://developer.apple.com/library/mac/#documentation/UserExperience/Reference/AddressBook/Classes/ABPerson_Class/Reference/Reference.html#//apple_ref/occ/instm/ABPerson/parentGroups
There is a method parentGroups which returns the array of groups to which the person belongs...........
I'm rolling my own PeoplePicker, using the following code to get all my contacts:
ABAddressBookRef ab = ABAddressBookCreate();
ABRecordRef source = ABAddressBookCopyDefaultSource(ab);
NSArray *allContacts = (NSArray *) ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(ab, source, ABPersonGetSortOrdering());
It's worked fine during development, but now we're in beta, and a user complained that when they went to choose a contact in my app, the list they were given to choose from was a small subset of all their contacts in their phone.
We pinned it down to the fact that it was actually just displaying one of their groups.
A while later, I realized you can set your default group in Settings > Mail, Contacts, Calendars > Contacts > Default Group
If a user has a specific group selected, then just that group displays in my app.
I think this is because I'm using ABAddressBookCopyDefaultSource to get all the contacts.
How can I grab all a user's contacts without regard to the default source?
Thanks!
try this,
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for( int i=0;i< nPeople;i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
.....
and so on
}