8

if the user changes the Camera permission, the app crashes in the background with Message from debugger: Terminated due to signal 9 .

They can now open up the app and the permission is correct, but they need to start from the beginning. Does anyone know how to fix this?

I need to prompt users to change camera permissions for my app via a UIAlertController. The alert has the following action:

alert.addAction(UIAlertAction(title: "Open Settings", style: .default, handler: { (action) -> Void in

    guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
        return
    }

    if UIApplication.shared.canOpenURL(settingsUrl) {
        DispatchQueue.main.async(execute: {
            UIApplication.shared.openURL(settingsUrl)
        })
    }
}))
Hardik Darji
  • 3,633
  • 1
  • 30
  • 30
  • 1
    Possible duplicate of [App crashes in background while changing permission - swift](https://stackoverflow.com/questions/43974752/app-crashes-in-background-while-changing-permission-swift) – SachinVsSachin Nov 22 '18 at 10:11

2 Answers2

15

This is not a problem of your application. Its just the way apple designed iOS. iOS will terminate the application when user change certain permissions of it.

Actually you will get a SIGKILL message but no Crash log when toggling settings. In this situation even applicationWillTerminate not get called!

So the answer is you can't fix it.

Look at page 24 of this slide

Sepehr Behroozi
  • 1,780
  • 1
  • 17
  • 32
  • Is there any statement by Apple where does it conclude for same? – Hardik Darji Nov 22 '18 at 11:56
  • 4
    Yes. Look at page 24. http://developer.apple.com/devcenter/download.action?path=/wwdc_2012/wwdc_2012_session_pdfs/session_710__privacy_support_in_ios_and_os_x.pdf – Sepehr Behroozi Nov 22 '18 at 12:24
  • Thanks sepehr. Data Isolation: • If permissions changes, app is quit ■ Background task expiration handler is called, if registered ■ iOS then kills the application – Hardik Darji Nov 22 '18 at 12:47
1

According to Apple privacy policies after iOS 6 for Data Isolation:

  • Builds on top of the sandbox
  • User permission gathered by iOS
  • Access to data is disallowed without user permission
  • If permissions changes, app is quit
  • Background task expiration handler is called, if registered
  • iOS then kills the application
Shashank Malviya
  • 670
  • 6
  • 17