How can I prevent iOS apps from resetting after changing Camera permissions?
I'm sure that there is no other ways to prevent restarting app. Actually you will get a SIGKILL message but no Crash log when toggling settings. See below links-
The only way to prevent this scenario is to save the previous state of you application while terminating.
- Store app your current data into a json/plist/NSUserDefaults/archive user model at applicationWillTerminate: method and
- restore saved data at applicationWillEnterForeground:
For example- @SignUpViewController register for UIApplicationWillTerminateNotification which will fire when the app is about to terminate. Store user information there.
- (void)viewDidLoad{ [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name: UIApplicationWillTerminateNotification object:nil];}- (void)applicationWillTerminate:(NSNotification *)notification{ // store your data here}
Hope this will help you:)
The accepted answer is correct, however the workaround does not appear to work in the current version of iOS (9.2) - the application seems to terminate before UIApplicationWillTerminateNotification is fired. However by listening to UIApplicationDidEnterBackgroundNotification, the same can be achieved. e.g in Swift, put this in viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "enteringBackground:", name: UIApplicationDidEnterBackgroundNotification, object: nil)
and have a function like this:
func enteringBackground(sender:AnyObject){ // Save application state here}