App crashes on enabling Camera Access from Settings iOS 8
Asked Answered
C

2

54

I am developing an app for iPhone, it is using camera for scanning barcodes and taking pictures. When we don't have Camera access and the user enables Camera Access, the app crashes and the re-opens.

Can you folks help me to fix this?

Thanks in advance.

Czernowitz answered 30/9, 2014 at 7:36 Comment(7)
I'm getting the same problem. App crashes when user toggles the camera access button in the app's settings page in iOS8 (either from enable->disable or disable->enable)Lienlienhard
I m also getting same problem..Trusteeship
did you found any solution...i m also getting same problem...i think this is related to os, not our coding..Ragen
It crashes when you running the App in debug mode. Normaly it is not crashing, it just restarts the app.Orthotropic
Happened same with me. Did you find any solution?Towering
Without code, this question may be off-topic: Questions seeking debugging help ("why isn't this code working the way I want?") must include: •the desired behavior, •a specific problem or error and •the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example, What topics can I ask about here?, and How to Ask.Skeleton
From iOS 10, NSCameraUsageDescription key should be set in app's info.plist. Key: NSCameraUsageDescription Value: Explain why do you need camera access.Lockyer
G
87

The first time you access the Camera the OS will automatically show the permission prompt. Whether the user allows or denies the prompt, your app will continue running. If the user at some point changes the Address Book, Calendars, Reminders, Camera, or Photos permissions, iOS will SIGKILL the app. It takes this action to ensure that the app no longer has any previously authorized data in its possession. When the user moves from the Settings app back to the third-party app, it launches from scratch and now has the Denied authorization status. As a result of this behavior, I have two recommendations:

  1. Detect when the permission is denied and present some UI that explaining that the user needs to toggle the Settings app permission. In iOS 8 you can take them directly to your app's entry with [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]].

  2. Implement some sort of state restoration so that when the app is terminated and relaunched it will return the user to the view/feature that was previously visible.

Source (requires developer account)

Gutow answered 17/4, 2015 at 18:54 Comment(10)
Just to clarify, would you recommend that this type of setting change not be done from within the iOS app itself, but from the settings part of the UI? I'm an interested 3rd party and it isn't clear from the OP where the settings change is being done.Ablation
The first time you access the Camera the OS will automatically show the permission prompt. Whether the user allows or denies the prompt, your app will continue running. If the user at some point changes the permission via the Settings app while the app is running, then it will be SIGKILLed.Gutow
I would recommend detecting when the permission is denied and presenting some UI that explains the user needs to toggle the Settings app permission. In iOS 8 you can take them right to your app's entry with [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]Gutow
Thanks. Comments may not be permanent, so please copy that information into your answer so it doesn't get lost.Ablation
Now that iOS 9+ supports deep linking and users can return directly to your app from settings screen, how can this issue be solved? Upon returning from settings screen (using status bar's back button) the app crashes and UI is unresponsive...Twinkling
@Twinkling I'm seeing the app get relaunched appropriately when using the status bar back button. If you're running the app in the debugger it is probably stopping on a breakpoint in main().Gutow
@Gutow I go to "Settings". Allow access to photos. Then get a SIGKILL error as expected from Apple killing app after permission change, then I return to app via status bar back button, and the PHAuthorizationStatus has not updated...Twinkling
@Twinkling Can you add a new question with your code and link it here?Gutow
Search for the word "kill" within this PDF: adcdownload.apple.com/wwdc_2012/wwdc_2012_session_pdfs/… iOS kills apps when certain permissions change. This info is hard to track down. It's not in any of the 'guides' (preferences programming guide, for example).Abiogenesis
Note: the link to Apple Discussions was likely broken with the new UI.Room
V
0

Your recommendations are correct. I present an alert view asking the user to go to the Settings app to change camera and contacts permission if they previously denied them. The problem for me is with your #2 recommendation. I am deep inside a sign up process and have collected sign up information such as name, email, date of birth. Then I have a "Request for Permissions" screen. When the app is relaunched after it's killed, I don't have this signup info anymore. I guess, I can save the signup info (to the phone) before presenting the alert view, then upon relaunch of the app, check if there is any previously stored sign up info. If so, go back to the screen which asked for permissions, then delete the stored sign up info.

Veterinarian answered 20/4, 2018 at 17:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.