23

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)
        })
    }
}))

This does work in so far as it opens the settings, but 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 solve this?

LC 웃
  • 18,888
  • 9
  • 57
  • 72
James
  • 459
  • 1
  • 3
  • 10

1 Answers1

69

Your app is not crashing its just forced to restart by iOS with new privacy settings. So when you change the camera permission then it means privacy policy changed, so app will be killed if its attached to debugger else it will relaunch.

Also, Not only camera permission If the user at some point changes the Address Book, Calendars, Reminders, Camera, or Photos permissions, iOS will SIGKILL the app. (it's default behaviour of iOS)

Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40
  • This seems to be it. Thanks for the info. – James May 15 '17 at 10:10
  • I just added exit(0) when i opened the camera settings. It's working fine – HariKarthick Oct 12 '17 at 10:40
  • When using a side-load attached to Xcode system: 1- app does restart 2- signal 9 is logged in debugger 3- Xcode is disconnected (I assume, the device restarts the process) – benc Nov 09 '17 at 01:32
  • 4
    @Jaydeep, do you have an "official" doc link where this behavior is explained ? thanks :) ! – Paul Aigueperse Apr 05 '18 at 19:01
  • 1
    @PaulAigueperse, Yes its available in official site. Please look at page number 24 https://download.developer.apple.com/wwdc_2012/wwdc_2012_session_pdfs/session_710__privacy_support_in_ios_and_os_x.pdf – seggy Nov 23 '22 at 05:00