views:

101

answers:

1

I would like to list all phone numbers (or any other field) of people in the addressbook.

I've written the following code:

- (void)addressBookFill{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    people = (NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
    [addressBook release];
}

- (void)printAddressBook{
    for(id person in people){
        NSLog(@"%@", [person class]);
        NSLog(@"\t%@", person );
    }
}

When I invoke the printAddressBook method I get this on my console:

2010-07-06 10:34:11.998 app[91420:207] __NSCFType
2010-07-06 10:34:11.999 app[91420:207]  <CPRecord: 0x5d56ce0 ABPerson>

And I don't have any idea, how to dereference this ABPerson object, how to get any info from it.

I tried:

firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);

but I got some exceptions.

Can anybody tell me how to get some info from these objects?

A: 

Read the documentation about the ABPerson class:
http://developer.apple.com/mac/library/documentation/UserExperience/Reference/AddressBook/Classes/ABPerson_Class/Reference/Reference.html

and also the ABRecord class:

http://developer.apple.com/mac/library/documentation/UserExperience/Reference/AddressBook/Classes/ABRecord_Class/Reference/Reference.html#//apple_ref/occ/cl/ABRecord

[ person valueForProperty: @"propName" ]

You can get the available properties with:

[ ABPerson properties ]

[ EDIT ]

On iPhone, you can use the following code to access a value:

NSString * lastName = (NSString *)ABRecordCopyValue( person, kABPersonLastNameProperty );
Macmade
I'm afraid there is no thing as ABPerson Class on iPhone. There's only some ABPersonRef or ABRecord like here:http://developer.apple.com/iphone/library/documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.htmlandhttp://developer.apple.com/iphone/library/documentation/AddressBook/Reference/ABRecordRef_iPhoneOS/Reference/reference.html#//apple_ref/c/func/ABRecordCopyValue
Alistra
See the edit : )
Macmade