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

前端 未结 2 1405
独厮守ぢ
独厮守ぢ 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:23

    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
    }
    
    0 讨论(0)
  • 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:)

    0 讨论(0)
提交回复
热议问题