0

I have implemented method to get contacts.

For iOS 6, I used below code to get permission from the user:

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);

Above code working fine in iOS 6 but below iOS 6 I am getting below error:

enter image description here

swati sharma
  • 367
  • 4
  • 15

2 Answers2

1

You can use MACROS to filter this:

#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

Let us know if it works.

Dilip Lilaramani
  • 1,126
  • 13
  • 28
0

Well, it seems you know the answer already. Both of those functions are iOS 6+ only, and do not exist in prior SDKs, meaning their symbols are undefined. You have to code to the lowest common denominator, or up your target to iOS 6.

CodaFi
  • 43,043
  • 8
  • 107
  • 153