19

I have an app that uses the ALAssets framework to access to the users photo library. I wrote some code that detects whether or not the app has permission to access the photo library, and if it doesn't, I display an alert message which tells the user to turn on location services for the app in settings.

Problem is, when the user manually changes the privacy settings and then they reopen the app, iOS forces the app to crash with SIGKILL.

I've noticed that the way another app handles this is by somehow detecting a change in the privacy settings, and forcing the app to restart the next time the user opens it. Does anyone know how to accomplish this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ser Pounce
  • 14,196
  • 18
  • 84
  • 169

2 Answers2

28

You misunderstand what is happening. Your app is not crashing (though it may appear so if you are running the app with the debugger).

When you switch to the Settings app (and your app is suspended in the background) and change the privacy settings, suspended apps are terminated. When you switch back to your app, it is simply started again. This is no different than your app being killed for any other reason.

It is up to you to code your app to handle this by restoring its previous state. The other app you talk about is simply returning the user to the previous state. Many apps do this. It has nothing to do with being killed due to privacy changes. The app would restore state when being killed for any reason.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thank you. When I was running the app from xCode, like you say, it appeared like it was freezing. But when I run the app just off of the phone, and then change the settings, the app reboots itself the next time it starts instead of freezing. – Ser Pounce Apr 10 '13 at 16:09
  • Is this specific to the Simulator? I tried changing the Twitter access on a device and it didn't cause my Twitter app to be killed. It came back from background as usual. – nevan king Apr 10 '13 at 16:10
  • @CoDEFRo When debugging through Xcode, you need to click the Stop button after the app crashes, then you can properly restart the app. – rmaddy Apr 10 '13 at 16:10
  • Right...in this instance it makes sense why it would freeze, because iOS is trying to restart it, but it's still connected to the debugger. Thanks again! – Ser Pounce Apr 10 '13 at 16:12
  • 3
    @rmaddy Please add Apple documentation – evya Mar 19 '18 at 07:17
1

You can check whether you're authorized to access the photo library using the authorizationStatus class method of ALAssetsLibrary. You should check this value in some method that will be called each time your app "opens", and update your UI accordingly.

bdesham
  • 15,430
  • 13
  • 79
  • 123
  • That's exactly what I am doing, and when I detect it, if it isn't authorized, I tell the user to go change it in the settings app. When they do go and change it, the app crashes. – Ser Pounce Apr 10 '13 at 16:00
  • It's not actually a method in my code that is crashing my app. The app is being crashed by iOS when the user changes the settings outside of the app. This explains it: http://stackoverflow.com/questions/12652502/app-killed-by-sigkill-when-changing-privacy-settings – Ser Pounce Apr 10 '13 at 16:03