views:

153

answers:

1

i dont know anything about obj-C and Xcode, almost nothing, i tried building only with very basic apps...

now i have here an app porject source, a friend of mine built partially, and i need to finish it.

the only thing i need is to save the string (a telephone number in my case) to the iphone address book

this is the var

resultText.text 

that has the string coming from a function... so i just need to find the right code to end the action btw, i already added the Adressbook /and UI frameworks

thanks!!!!

A: 

Here, you will need to link the the ABAddressBook framework first though. To do that, you will need to (in XCode) goto Project > Edit active target "TargetNameHere.app". Press the add button on the lower left hand corner, and find AddressBook.framework (is usually the first there). Click add.

import <AddressBook/AddressBook.h>

// CODE BETWEEN START OF FILE AND ADDING ADRESS BOOK ENTRY.

ABAddressBookRef ab = ABGetSharedAddressBook();
// To add a new ab entry with telephone number
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @"Bob", nil);
ABRecordSetValue(newPerson, kABPersonLastNameProperty, @"Jones", nil);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, resultText.text, nil);

ABAddressBookAddRecord(ab, newPerson, nil);
ABAddressBookSave(ab);

For the sake of space, I didn't check for NULL, or pass in error pointers and check for errors, but you should do this.

This code should go in a .m file of the class that wants to add an Address Book entry; most likely in the function that currently has access to resultText.text.

cool_me5000
i think there are typos#import <AddressBook/AddressBook.h>and // instead of \\
camelCase
also, i still dont get where to place this code?? wich file? i think my main problem here in xcode is to undestrand the organizations of the files... it sounds like a mix between flash and js...but i don tget the difference between a file . h or .m etc...
camelCase
OK. A .m is where you put your actual code that does stuff. Usually the code goes in a method inside your class implementation. A .h is where you declare which variables will be present in your class, and which methods other files can use. This code should be put in the method that you get your result.text in.
cool_me5000