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

前端 未结 2 1422
独厮守ぢ
独厮守ぢ 2020-12-14 19:47

Currently, when I change the camera permissions for my app in Settings, then navigate back to my app, the app will force a refresh and I will lose my place in the app. I fol

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 20:24

    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-

    • https://devforums.apple.com/message/715855
    • https://devforums.apple.com/message/714178

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

提交回复
热议问题