我正在尝试获取iOS(5.0 +)上的地址簿条目的名称和出生日期,我找到了documentation和{{{{}}这样做的方法3}}。但我总是得到标题中提到的所有'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;
}
答案 0 :(得分:1)
看起来您使用的常量特定于Mac OS X.其版本ABRecordCopyValue
的iOS文档会导致kABPersonNicknameProperty
等常量名称。