1

I am using below Code, My application don't ask permission on iOS 6 while on iOS 7 and above version it ask for Contact permission access. On iOS 6 it doesn't show app in privacy setting as well. I have read some other thread but not found any solutions.

App crashed in iOS 6 when user changes Contacts access permissions

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {

    __block CDNDeviceContact *controller = self;

    // Request authorization to Address Book
    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {

        ABAddressBookRequestAccessWithCompletion(addressBookRef,
                                                 ^(bool granted, CFErrorRef error) {
                                                     if (granted)
                                                         [controller loadContacts];
                                                     else [controller doAlertForContact];
                                                 });
    } else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {

        // The user has previously given access, add the contact
        [self loadContacts];
    } else {
        [controller doAlertForContact];
    }
    if (addressBookRef)  CFRelease(addressBookRef);
}
Community
  • 1
  • 1
Mangesh
  • 2,257
  • 4
  • 24
  • 51

2 Answers2

2

If the user has previously been presented with the request to get permission, it will not show again. According to the documentation,

The user is only asked for permission the first time you request access. Later calls use the permission granted by the user.

If testing in the simulator, I recommend that you go to iOS Simulator -> Reset Content and Settings so that you are able to simulate the event.

erdekhayser
  • 6,537
  • 2
  • 37
  • 69
0

You don't need SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO and you also don't need to create an ABAddressBookRef.

For me, this is works like a charm:

if (ABAddressBookGetAuthorizationStatus) {
    switch (ABAddressBookGetAuthorizationStatus()) {
        case kABAuthorizationStatusNotDetermined:{
            ABAddressBookRequestAccessWithCompletion(self.addressBook, ^(bool granted, CFErrorRef error) {
                self.addContactButton.enabled = granted;
                if (granted) {
                    // granted
                } else {
                    // User denied access
                }});
        } break;

        case kABAuthorizationStatusDenied: break;
        case kABAuthorizationStatusAuthorized: break;
        default: break;
    }
}
Laszlo
  • 2,803
  • 2
  • 28
  • 33