Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Address Book: List Sources and Accounts

Tags:

I need to select the address book source in which contacts are created by my app.

In the Contacts app, when I select "< Groups", I get the options

  • All Contacts
  • MobileMe
    • All MobileMe
    • Company
    • Family
    • Friends
  • ACME Exchange
    • ACME Exchange Global Address List
  • Test CardDAV
    • Addressbook
    • Search

Using the function ABAddressBookCopyArrayOfAllSources I get source records for

  • No name; type: kABSourceTypeMobileMe
  • No name; type: kABSourceTypeExchangeGAL
  • "Addressbook"; type: kABSourceTypeCardDAV
  • "Search"; type: kABSourceTypeCardDAVSearch

The names are in no way descriptive and I would like to show the account names in addition to the source name or type, just like the Contact app does.

Do you know a way to find out the account name of a source, or to retrieve all existing account names and the sources of each account? Any other ideas to get more descriptive entries?

like image 839
Michael Manner Avatar asked Dec 07 '10 12:12

Michael Manner


People also ask

Where are addresses stored in iPhone?

It's in your contact record in the Contacts app. For any of your contacts you can Edit to change addresses, add additional address locations as well as all other type of contact information.

How do you manage your address book on iPhone?

Go to Settings > Contacts > Accounts. Tap the account that has contacts that you want to add or remove. To add contacts, turn on Contacts. To remove contacts, turn off Contacts, then tap Delete from My iPhone.

Where are Contacts stored on iPhone file system?

In the Applications Support Folder there is a Folder called AddressBook. In this folder is a folder called Metadata. In here are files, one for each contact.


1 Answers

As of iOS 5.1 there is no public API for this.

One would hope that ABRecordCopyCompositeName() would get what you're after — it provides the "human friendly" name for Person and Group records — but alas it returns null.

As Graham pointed out (when offering a bounty) directly asking for kABSourceNameProperty provides the wrong answer.

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);

CFIndex i, c = CFArrayGetCount(sources);
ABRecordRef curSource;

// Log each source name.
for (i=0; i<c; i++) {
    curSource = CFArrayGetValueAtIndex(sources, i);
    NSString *name = (__bridge_transfer NSString *)ABRecordCopyCompositeName(curSource);
    NSLog(@"Alas this is null: %@", name);


    NSString *directValue = (__bridge_transfer NSString *)ABRecordCopyValue(curSource,kABSourceNameProperty);
    NSLog(@"And direct access gives wrong answer: %@", directValue);

}

CFRelease(sources);
CFRelease(addressBook);

All I can suggest is filing a Radar to ask that ABRecordCopyCompositeName() be made to make whatever service Contacts itself is using available to the rest of us.

like image 102
Carlton Gibson Avatar answered Oct 06 '22 00:10

Carlton Gibson