To get all contacts I'm using ABAddressBookCopyArrayOfAllPeople method but, this method return all contacts with duplicates: in "Contacts" app I saw that almost every my contacts has linked card (it's show me that I have two same contacts one from iCloud and an other from my iPad). As I see in this reason ABAddressBookCopyArrayOfAllPeople method return duplicate contacts.
How to get all contacts from ABAddressBook without duplicate?
Maybe the ABContactHelper could help?!
From memory I think this returns only one record per user:
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
addressBookArray = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByLastName);
I've used it an it appears to work. Although you will have to jump through the linked contacts to get all the details about a user.
Remember to CFRelease source and addressBook when you are finished.
I had the same problem and did not find another solution then the manual bidirectional-link-duplicate-removal process:
Two cascaded cycles (ordo n^2) that confronts the record ID of each contact-pair that was returned by ABAddressBookCopyArrayOfAllPeople. Then I add to the final list only the contact with the smaller contact ID. It's not very beautiful solution but it works for me.
Related
I am making an app that the user could add many accounts and view it in the UITableView and I am holding the name via NSUserDefaults and once the name is clicked in the UITableView it will open a different page that has many data fields to fill which is DONE.
For example when the user click on John or other name. The user could see his own data. My problem is that how could I show for every user his own data? Also could I make this via NSUserDefaults ?
It smiler to contacts tab in the iPhone. I hope I could explain my problem.
My source code I hope it helps Download Link
This answer hasn't common answer without knowing your architecture and data which you show in table. Generally database greatly solve this problem - you store all data in db and fetch by predicate only needed data -
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"name== %#", userName];
NSArray *orders = [Order findAllUsingPredicate:predicate]; // this is prototype method
But database is being used for large amount of data, and if you don't want to use db or have static data to display then look at plists. You can create plist with nodes
-John
-Order1,Order2
-Mike
-Order3,Order4,Order5
...
Then read this file, and fetch John's object like this:
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:pathToPlist];
johnsObjects = [dict objectForKey:#"John"];
Hope, it will be helpful for you
Use a document-based app (UIDocument). Give each user his own document. Switch between documents when you switch users. See Document-Based App Programming Guide for iOS.
I'm trying to use ABPersonGetCompositeNameFormat() to read the sort order settings for the user's address book. It always returns kABPersonCompositeNameFormatFirstNameFirst regardless of how I configure the "Display Order" preference in the Settings application. The Address Book application changes appropriately when the display order is set to "Last First" but the API call always returns the same value that represents the "First Last" display order. Has anybody else had this problem? I'm running this on an iPhone4 with iOS 4.3.3.
I've just found a solution - ABAddressBookRef has to be obtained (by ABAddressBookCreate) at least once before calling to ABPersonGetCompositeNameFormat(), but there are no mentions about it in the documentation.
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
people = (NSArray*)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByLastName);
It helps you.
I am wanting to create a contact programmatically into the "local" addressbook (so that it doesn't try to synch, which causes some compatibility issues with Exchange).
If a local addressbook already exists, I can find it using ABAddressBookCopyArrayOfAllSources to get all the sources in the Address Book, then look for the ABRecordRef with a sourceTypeRef of "kABSourceTypeLocal"- if I then pass that recordRef to ABPersonCreateInSource, I can add a record to the local directory.
Does anyone have any suggestions as to how I should best go about creating a record in the "local addressBook", if there ISN'T a local addressbook already?
(also, how could I do this pre-iOS4, as the above calls weren't available then?)
Thanks
Peter
You should take a look at this post:
Obtaining Specific ABSource from ABAddressBook in iOS 4+
that demonstrates how to identify and target specific sources (ABSource) within the ABAddressBook. While this code mentions the function, ABGroupCreateInSource(), there is a similar function, ABPersonCreateInSource() for working with persons.
I found a simple workaround.
Since you can't see/add local contacts when you don't have any pre-existing local contact, the following workaround will be safe to use:
Let's pretend you're using Gmail (Exchange)
Go to your Mail settings for Gmail and disable the Contact sync
When prompted whether you want to keep or remove the Gmail
contacts from your phone, choose to REMOVE them (don't worry, they
won't be removed from Gmail)
Go back to your contacts. You can now create one LOCAL contact
Finally, go back to Settings/Mail/Gmail and re-enable the
Contacts sync
Voila, your Gmail contacts are back into your phone and you now
have 1 local contact that enables you to access the Local contacts
group in addition to the Gmail contacts group.
Hope that helps (I just had the same problem and found this workaround that works great for me).
Ben.
Hi i am developing an app for my QA department. I need to programically get how many phone numbers are there in the entire address book. No user input. Just click a button and then get how many phonenumbers are there in the ENTIRE addressbook.
I think what you are looking for is ABGroupCopyArrayOfAllMembers. See the AddressBook Programming Guide and the QuickContacts example for more info on using the AB framework.
from what I can tell from a quick look at ABMultiValue in AddressBook.sqlitedb, you might get it like this:
1 - sqlite to /var/mobile/Library/AddressBook/AddressBook.sqlitedb
2 - SELECT value FROM ABMultiValue => into some array
3 - count everything in there that matches /^[0-9 +]+$/
look around for some more help doing these steps
Edit: there's probably also some way to do it with this method:
How do you get a persons phone number from the address book?
Can I create an ABAddressBook which does not read data from my address book. i.e. it's empty to start with so that I can put in my own contacts fetched from the internet.
As you may know the function
ABAddressBookRef ab = ABAddressBookCreate();
gives me data from the built in addressbook. This is not what I want but if you know a solution to my problem please let me know.
I don't think it is possible to have an empty instance of ABAddressBook. The documentation is only about getting an ABAddressBook filled with the address book of the iPhone.
You could try making an array (or mutablearray) that you fill with the contacts and put the array inside a UITableView.
I've been working on a "private contacts" app which stores contacts off of the normal address book and I can confirm that this is indeed possible, if only through a little manipulation. Using the ABAddressBookRef variable, however, won't help you at all. What you need is a NSMutableArray of ABRecordRef's, which is how iOS stores its contacts.
You could try to zero out ABAddressBookRef with a memset/calloc and see if that gives you the desired result.