42

I have an app that uses the iPhone's contacts. With iOS 6, the user will be prompted for Contact access on the first try. At this point, the user can hit 'Allow' or 'Don't Allow'. The problem is when the user backgrounds the app, and then navigates to Settings->Privacy->Contacts to toggle the Contact privacy setting for my app. Once it is toggled, I can see on the console that my app:

Application 'UIKitApplication:com.myApp' exited abnormally with signal 9: Killed: 9

I can't find any information on this in Apple's documentation. Does anyone know a way to prevent this? Is this as designed? Or is this an Apple bug?

rocky
  • 3,375
  • 1
  • 19
  • 30
  • 2
    I am getting similar behavior on the contacts. I experimented with the photo privacy settings and my app also crashes if that is toggled while the app is in the background. Consider adding additional tags to your question, 'iphone' 'addressbook' 'objectivec' which might increase its visibility. – Mike Sep 22 '12 at 09:52
  • Happens to me as well. This seems like an Apple bug. – Tal Bereznitskey Sep 23 '12 at 12:44
  • 1
    Apple Bug Reporter Problem ID: 12360315 – rocky Sep 24 '12 at 18:56
  • I see this same issue with contacts privacy. My app crashes in the background if the privacy settings for contacts are toggled. The only mention of a hook into this is in the "What's New in iOS" Data Privacy section. "If the user grants permission to the app, the system subsequently notifies the app that it needs to reload or revert the data." [link](https://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iOS6.html#//apple_ref/doc/uid/TP40011812-SW1) Anyone know how to handle this notification or what it is called? – process255 Sep 25 '12 at 19:12
  • I've been scouring the interwebz for this notification but no dice. =( – rocky Sep 25 '12 at 21:39
  • I haven't found a notification; however, be aware that when running the app normally (not via simulator or device debugging), the app will be automatically restarted. So, if you handle a restart well, your app should be fine. – leanne May 04 '14 at 22:15
  • 1
    It still happens in ios8. – Yijun Jun 25 '15 at 02:41

2 Answers2

73

the OS sends a SIGKILL which is not a crash - Apple session on privacy in iOS6 says:

  • If permissions changes, app is quit.
  • Background task expiration handler is called, if registered
  • iOS then kills the application.

WWDC 2012 Session Videos: Privacy Support in iOS and OS X

Expiration handler: beginBackgroundTaskWithExpirationHandler

There is no way around this I can see.

Community
  • 1
  • 1
amleszk
  • 5,834
  • 4
  • 34
  • 41
  • This is it. Thanks for the post. – rocky Oct 04 '12 at 19:57
  • 4
    App also quits in iOS7. Note, though: if running the app on the device normally - NOT in Xcode debugging - the app will automatically be relaunched after the permissions have changed. The user won't see that a crash occurred (assuming, of course, that the app handles everything properly on restart). – leanne May 04 '14 at 22:13
  • This appears to not hole true for **Location permissions** (at least in iOS 8)? – Warpling Jul 07 '15 at 23:30
  • 1
    I have created a background task with expiration handler but the handler is not called when changing permission settings. Any ideas ? – Blazej SLEBODA Sep 02 '15 at 16:24
  • But in the simulator, you can still press the "Resume" button to continue execution. While in devices you cannot. – jchnxu Dec 11 '16 at 16:05
  • How to stop killing the application? I checked some apps(skype and whats app) they are not restarting when privacy changes – siva krishna Apr 03 '17 at 07:38
  • But keep in mind that if your app uses state restoration, when the user switches back to your app it may appear to the user that nothing happened, because your app restores its state. Of course, the app UI may need to look different if the user disabled something that you need. – Kenster999 Sep 12 '18 at 22:02
2

After testing beginBackgroundTaskWithExpirationHandler I can say that expiration handler block is not called after changing permission settings as stated in Apple presentation.

Blazej SLEBODA
  • 6,503
  • 3
  • 35
  • 69