6

My iOS app needs the privilege to access pictures to run properly.

I was testing how my app was responding to changes in the privacy settings when I discovered the following: each time I go to the Settings apps and change the privacy setting for my app (either turning it on or off), my app is killed without any warning.

I found these logs in my device's console:

Apr  8 15:01:50 iPad Preferences[5924] <Warning>: ########### Quitting application (xxx) in response to privacy settings change.
Apr  8 15:01:50 iPad com.apple.launchd[1] (UIKitApplication:xxx[0xc7cb][6039]) <Notice>: (UIKitApplication:com.edupad.itoochdev[0xc7cb]) Exited: Killed: 9
Apr  8 15:01:50 iPad backboardd[30] <Warning>: Application 'UIKitApplication:xxx[0xc7cb]' exited abnormally with signal 9: Killed: 9

And though I implement applicationWillTerminate: in my app delegate, it doesn't seem to get called before the app is killed.

I can't find any relevant documentation about what I should implement to get a notification before my app is killed. Any idea if I can solve this?

PS 1: i know i could implement applicationDidEnterBackground: but I would like to provide a different UX in the case (A) the user just quickly switched to the Setting app to change the privacy setting or (B) the user wants to move on and won't be back to the app before a while

PS 2: if you're testing this sort of things, don't do it with your app being launched via Xcode or you'll crash with a sigkill.

Mick F
  • 7,312
  • 6
  • 51
  • 98
  • You always must expect that your app could get killed after it switches to the background. Even if the user quickly goes to privacy settings, they can then remember something else, go to a different app, and so on. So the only possibility you have is probably checking how much time was spent between entering background and foreground. – gnasher729 Jun 03 '15 at 13:30

1 Answers1

0

Typically in cases where you would want to save state or clean up code before your app gets killed, you would need to define the block beginBackgroundTaskWithExpirationHandler.

You can take a look at Apple's WWDC 2012 docs which talks about what happens when privacy settings are changed iOS6 onwards. In brief, it says that beginBackgroundTaskWithExpirationHandler gets called before a SIGKILL is sent so you could handle clean up code there.

There's another discussion on Stack Overflow along the same lines. It would be helpful if someone could find it and link it here.

Shwethascar
  • 1,142
  • 9
  • 18