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;
}