What is the correct way to save NSUserDefaults when my app is terminated on iOS

后端 未结 4 916
不知归路
不知归路 2021-02-10 03:16

I need to save my NSUserDefault when my app is completely quit in iOS. not didenterbackground and foreground. Only when user kill my app w

4条回答
  •  别跟我提以往
    2021-02-10 03:42

    From Apple Doc :

    For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.

    It's not necessary that applicationWillTerminate will be called when app exits, it may not be called when your app supports background execution.

    You can use UIApplicationExitsOnSuspend to specifies that the app should be terminated rather than moved to the background when it is quit.

    I afraid, there isn't any delegate method which will surly handle app's force-quite scenario.

    Hope this may help you in solving your problem.

提交回复
热议问题