我已经实现了获取联系人的方法。
对于 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 下我得到以下错误: