ABAddressBook - multiple address books? - iphone

I am building an app which syncs contacts from an online source. Everything works fine so far...when the phone has one address book:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef group1 = ABGroupCreate();
ABRecordSetValue(group1,kABGroupNameProperty,#"Group1",nil);
ABAddressBookAddRecord(addressBook,group1,nil);
ABAddressBookSave(addressBook,nil);
ABRecordRef person = ABPersonCreate();
// Edit person values...
ABGroupAddMember(group1,person,nil);
ABAddressBookAddRecord(addressBook,person,nil);
ABAddressBookSave(addressBook,nil);
CFRelease(person);
CFRelease(addressBook);
The problem occurs, however when the phone already has multiple address books. I am testing on a phone that has one address book for All Contacts, one for Gmail, etc. When I add a contact in the above manner, it adds it to the Gmail address book, and in the process strips the "Group1" identifier from the contact. Is there a way I can change the ABAddressBookRef to point to a specific address book within the phone?

According to the reference, ABAddressBookCreate always returns an address book object populated from the system's address book database. Which means there is only ever one address book, even if you have multiple instances of ABAddressBook that you use to interact with it.

Mike, you might want to take a look at this post:
Obtaining Specific ABSource from ABAddressBook in iOS 4+
Although I believe Alex is right that there is only ever one address book, that address book may consist of multiple sources (ABSource). And, in iOS 4+ it is possible to specifically identify and manipulate particular sources.

Related

Showing custom contacts like iphone Address book

I have tried
http://zcentric.com/2008/09/19/access-the-address-book/
And it works great. But now instead of AddressBook contact i have an array or other structure that have my contacts and i want to show it like an Address Book.
Do i need to make it all custom or is there any way i can use the AddressBook to show my contacts?
Using ABPeoplePickerNavigationController you can only fetch the contacts from the Ipad or Iphone Address Book.
If you want same functionality with your structure data you need to make it all Custom Using UITableView and other views.
read Addressbook Programming Guid here from apple and you will get detailed answer of your question.

Can I set up a seperated addressbook from the deafult one for iPhone?

can I set up a seperated addressbook from the deafult one for iPhone ?
I need this because for the app I am developing I need to add contact information for some special events; also I need to add contact information from work. I don't want to mix these contacts with the default addressbook(and I have other way to sync them). So is there a way to do it ?
Thanks!
there are two approaches by which the process could be done in your case first- there is no way that if you create a contact and when you sync it with the address book it will be saved in the address book data base and the contact will be there nothing the way that you add a contact in your app and the contact only highlight in your app only because the addressbook having only one database and adding and deleting contacts will effect the global database of the addresbook.Second thing you can maintain the your app database by which you can make the UI and the other part of the app like addressbook of iphone and just save those contacts in your database not in the addresbook database.Only these ways you have.

Getting list of contacts from phone book in Iphone application

I just want the all contacts list in my application, in NSArray or NSDictionary object or in any other form. My intense is that my application do also have its own contacts. Now I want to show my application's contact and native contacts in my application's phone book. So I just want the list of native contacts in some way so that I can show it along with my application's contact list. Thanks in advance........
Apple has a programming guide for the address book framework that should give all the information you need:
Address Book Programming Guide for iOS

iPhone Address Book custom property

I am developing an application which is similar to native contact book app of iphone. I want to add additional property/field in native iphone address book database. e.g. network carrier of each contact (AT&T).
How to access the database of native address book from our app? Is that possible to do?
You cannot add custom fields. You can add data into the Notes field, but not add any custom fields into the AddressBook Person class. You can extend the AddressBook but you will need to save the data somewhere else and link the Person to the data you saved.
You can access the data from the address book using the AddressBook framework.
addPropertiesAndTypes is only available on Mac OS

How to share contacts?

By using IPhone SDK (on a jail broken iPhone), how can I share a contact (.vcf file) through mail as same as the address book is doing?
Regards,
Prathap.
Have you looked at the Address Book Framework reference? It allows you to fetch records from the Address Book database. You may have to put this data in vCard format yourself, I don't know if the framework provides this functionality for you.
Yes, you can do this on the iPhone:
ABAddressBookRef addressBook = CFAutorelease(ABAddressBookCreate());
NSArray* contacts = (NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
Erica Sadun's ABContactHelper classes come in mighty handy if you want to mess around with the Address Book interface.