App crashed in iOS 6 when user changes Contacts access permissions

10,612

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.

Share:
10,612

Related videos on Youtube

Endzior
Author by

Endzior

Engineering Manager at http://songkick.com

Updated on May 20, 2020

Comments

  • Endzior
    Endzior about 4 years

    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?

    • Endzior
      Endzior over 11 years
      As per rmaddy's answer below, this is not a crash, it's iOS terminating the app.
    • Programmer...
      Programmer... over 11 years
      Same issue for me too but it's for Location Permission for my app :(
  • Albert Renshaw
    Albert Renshaw over 10 years
    Verified this also happens with photo security settings on iOS 7.0.3. Seems logical on Apple's behalf, no complaints here! Does anyone know a way to run background code to save some data before the app crashes due to security updates?
  • Pavan
    Pavan over 10 years
    Verified, this also happens with the microphone security settings in iOS 7.0.3.
  • leanne
    leanne about 10 years
    Works the same in iOS 7 Calendar-related apps. If you run the app on the device, NOT through Xcode debugging or simulator, you'll see that the app restarts, invisible to the user. So, as rmaddy says, just make sure your app does "a good job restoring app state upon a full restart ..."
  • russbishop
    russbishop almost 7 years
    This is deliberate behavior. If you change app permissions while the app is running it will be killed.
  • Kacper Cz
    Kacper Cz almost 7 years
    In my opinion best practice is to request permissions the moment the app needs to use these data (eg. when entering a certain screen).