How can I prevent iOS apps from resetting after changing Camera permissions?

人盡茶涼 提交于 2019-11-29 01:55:38

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!