0

我已经实现了获取联系人的方法。

对于 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 下我得到以下错误:

在此处输入图像描述

4

2 回答 2

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

让我们知道它是否有效。

于 2012-11-23T11:59:32.477 回答
0

好吧,看来你已经知道答案了。这两个函数都仅限于 iOS 6+ ,并且在之前的 SDK 中不存在,这意味着它们的符号是未定义的。你必须编码到最小的公分母,或者将你的目标提高到 iOS 6。

于 2012-11-23T10:17:33.207 回答