我正在尝试在 iOS (5.0+) 上获取地址簿条目的姓名和出生日期,并且我通过文档和这篇文章找到了这样做的方法。但是我总是得到标题中提到的所有“kAB ...”常量的错误,尽管我确定我在我的项目中链接了两个库 AddressBook 和 AddressBookUI。
有谁知道我做错了什么?
这是我的代码:
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
// 一些其他代码...
- (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;
}