PDA

View Full Version : source code for address book




AmitSrivastava
May 13, 2009, 12:56 AM
hi everyone,
This is my second week in iphone programing,
i have to make a contact wizard for iphone, i have allready designed the view for contact wizard using navigation controller, there are 3 pages total which includes UITextFields, PickerView, and Table View.
Now i dont know where to write code for add contacts in address book database.
can any one help me by some code sample...?????

i have written code in a function which is called on the Navigation toolbar Button
the code is

ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
ABRecordSetValue(aRecord, kABPersonFirstNameProperty,
CFSTR("Jijo"), &anError);
ABRecordSetValue(aRecord, kABPersonLastNameProperty,
CFSTR("Pulikkottil"), &anError);
if (anError != NULL) {

NSLog(@"error while creating..");
}
CFStringRef firstName, lastName;
firstName = ABRecordCopyValue(aRecord, kABPersonFirstNameProperty);
lastName = ABRecordCopyValue(aRecord, kABPersonLastNameProperty);




ABAddressBookRef addressBook;
CFErrorRef error = NULL;
addressBook = ABAddressBookCreate();

BOOL isAdded = ABAddressBookAddRecord (
addressBook,
aRecord,
&error
);

if(isAdded){

NSLog(@"added..");
}
if (error != NULL) {
NSLog(@"ABAddressBookAddRecord %@", error);
}
error = NULL;

BOOL isSaved = ABAddressBookSave (
addressBook,
&error
);

if(isSaved){

NSLog(@"saved..");
}

if (error != NULL) {
NSLog(@"ABAddressBookSave %@", error);
}

CFRelease(aRecord);
CFRelease(firstName);
CFRelease(lastName);
CFRelease(addressBook);


But it is showing many errors.

can any one give me some advice how to manage it?



david.david
May 28, 2009, 12:46 AM
hi add

AddressBook.framework


and
#import <AddressBook/AddressBook.h>