Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AmitSrivastava

macrumors newbie
Original poster
May 12, 2009
1
0
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.