我已经实施了获取联系人的方法。
对于iOS 6,我使用以下代码获取用户的许可:
CFErrorRef myError = NULL;
ABAddressBookRef myAddressBook = ABAddressBookCreateWithOptions(NULL, &myError);
ABAddressBookRequestAccessWithCompletion(myAddressBook,^(bool granted, CFErrorRef error)
{
if(granted)
{
[self GetContactInformation];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Contacts" message:@"You didn't permit us to access your contact details." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
});
CFRelease(myAddressBook);
以上代码在iOS 6中工作正常,但在iOS 6以下我收到以下错误:
答案 0 :(得分:1)
您可以使用MACROS对此进行过滤:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
CFErrorRef myError = NULL;
ABAddressBookRef myAddressBook = ABAddressBookCreateWithOptions(NULL, &myError);
ABAddressBookRequestAccessWithCompletion(myAddressBook,^(bool granted, CFErrorRef error)
{
if(granted)
{
[self GetContactInformation];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Contacts" message:@"You didn't permit us to access your contact details." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
});
CFRelease(myAddressBook);
#else
[self GetContactInformation];
#endif
告诉我们是否有效。
答案 1 :(得分:0)
好吧,看来你已经知道了答案。这两个功能都是iOS 6+ 仅 ,并且在以前的SDK中不存在,这意味着它们的符号未定义。您必须编码为最低公分母,或将目标提升至iOS 6。