0

I'm trying to fetch the name and birth date of an address book entry on iOS (5.0+) and I found a way of doing so with the documentation and this post. But I always get the error mentioned in the title for all the 'kAB...' constants although I'm sure I linked the two libraries AddressBook and AddressBookUI in my project.

Does anyone know what I do wrong?

Here's my code:

#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

// some other code ...

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    NSString *name;

    if ((NSString *)ABRecordCopyValue(person, kABNicknameProperty) != nil) {
        name = (NSString *)ABRecordCopyValue(person, kABNicknameProperty);
    } else if ((NSString *)ABRecordCopyValue(person, kABFirstNameProperty) != nil) {
        name = (NSString *)ABRecordCopyValue(person, kABFirstNameProperty);
    } else if ((NSString *)ABRecordCopyValue(person, kABLastNameProperty) != nil) {
        name = (NSString *)ABRecordCopyValue(person, kABLastNameProperty);
    }

    int birthYear;
    if ((NSDate *)ABRecordCopyValue(person, kABBirthdayProperty) != nil) {
        NSDate *birthDate = (NSDate *)ABRecordCopyValue(person, kABBirthdayProperty) != nil;
        NSCalendar *cal = [[NSCalendar alloc] init];
        NSDateComponents *components = [cal components:0 fromDate:birthDate];
        birthYear = [components year];
    }

    // do something with name and birth year
    [self dismissModalViewControllerAnimated:YES];

    return NO;
}
CGee
  • 1,650
  • 5
  • 20
  • 31

1 Answers1

1

It looks as though the constants you're using are specific to Mac OS X. The iOS documentation for its version of ABRecordCopyValue leads to constant names such as kABPersonNicknameProperty.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • Thanks! So I forgot the 'Person' in the constant names - didn't see this. Now it's all working as expected (although there are still some issues with type conversion ... but I'll work them out). :) – CGee Nov 21 '12 at 13:56