iPhone Address Book: List Sources and Accounts
Asked Answered
A

2

20

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?

Amabelle answered 7/12, 2010 at 12:50 Comment(1)
Did you find out, how to list the account names? i.e. in your example: ACME Exchange or Test CardDAVChefoo
R
4

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.

Roping answered 26/4, 2012 at 14:8 Comment(1)
Thanks for that, unfortunately ABRecordCopyCompositeName()'s documentation includes "The behavior of this function is not defined for source records." so I wasn't expecting it to work :-(Concertmaster
D
0

This may help:

Obtaining Specific ABSource from ABAddressBook in iOS 4+

iOS 4+ provides new API that allows one to select a specific ABSource from the ABAddressBook. This may be useful as some operations, e.g. creating an ABGroup, are not supported in some sources (i.e. Exchange).

"Not all source types support groups, more conspicuously, Exchange does not know anything about groups." - http://flavors.me/volonbolon#1a5/tumblr

It shows how functions can be used that leverage the new API to obtain sources of specific types which may be used in calls to ABGroupCreateInSource(), which looks to be what you're after.

Dogtired answered 9/11, 2011 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.