0

I dont know anything about Objective-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!

Maksim
  • 2,054
  • 3
  • 17
  • 33
Francesco
  • 24,839
  • 29
  • 105
  • 152

1 Answers1

0

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.

Stone Mason
  • 2,015
  • 2
  • 16
  • 19
  • i think there are typos #import and // instead of \\ – Francesco Sep 18 '10 at 18:06
  • 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... – Francesco Sep 18 '10 at 18:07
  • 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. – Stone Mason Sep 19 '10 at 05:32