Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashed in iOS 6 when user changes Contacts access permissions

I have an app that uses the Address Book. When running in iOS 6 it runs this code when the user does something that requires Address Book access.

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {     ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);      ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error)     {         if (granted)         {             showContactChooser();         }     });      CFRelease(addressBookRef); } else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {     showContactChooser(); } else {     showAccessDeniedAlert(); } 

This works perfectly: I am able to read the contacts information and when the user denied access, the app reacts accordingly.

However, if the user:

  1. Allows Contacts access in the app,
  2. Quits the app,
  3. Goes to Settings->Privacy->Contacts and disables Contacts access for the app,
  4. Runs the app,
  5. While the app is running in background goes to settings and enables Contact access for the app,

the app immediately crashes inside main() with no exception information or a meaningful stack trace. I tried turning on the "all exceptions" and [NSException raise] breakpoint, but that didn't give me any more information.

The crash can be reproduced even if the app doesn't run the above code during the launch.

What's happening here? Is there a callback that I should be subscribing to?

like image 276
Alexey Blinov Avatar asked Oct 10 '12 01:10

Alexey Blinov


People also ask

How do I fix app permissions on my iPhone?

From the Settings app, tap Privacy to see all the permissions available on your phone: access to photos, motion and fitness data, your phone's location, and so on. Tap on any entry to see the apps granted those permissions and to disable those permissions, if necessary.

What happens when you allow an app access to your contacts?

Contacts: With permission to read, change, and add contacts in your address book, and access the list of accounts registered in the smartphone, an app can send your entire address book to its server.


1 Answers

I've seen this in my own app. And I've seen others report this as well. I'm pretty sure this is deliberate behavior. The OS kills any background apps that react to changes in privacy permissions. Apple appears to have taken a sledgehammer approach to this. It's not a crash (though it may appear so when running in the debugger). Apps get terminated for various other reasons. Add this to the list of reasons. This gives us more reason to do a good job restoring app state upon a full restart of our apps.

Note that this behavior applies to all of the various privacy settings such as contacts, photos, microphone, calendar, and camera.

like image 172
rmaddy Avatar answered Oct 12 '22 22:10

rmaddy