Delete data when app is killed in the background.

前端 未结 3 681
误落风尘
误落风尘 2021-01-28 11:55

I have an app where I am saving data but when the app is killed in the background I have to delete all the saved data.

I tried using this method:

- (void         


        
相关标签:
3条回答
  • 2021-01-28 12:41

    Not sure why you need to wipe the data on terminate specifically, but here is something to consider:

    Another way to handle this type of situation when apps write data that may be incomplete when they are forced to quit, is that they write out a flag when the data is known to be good.

    That way, if the app exits normally, the data will be written and the flag will be written.

    If the app is forced to quit, the flag will not get written by nature of the forced quit.

    THEN, when the app starts it can look for the flag. If the flag isn't there, the app knows that any data is incomplete and can discard it (delete it) and start over.

    Hope this helps.

    0 讨论(0)
  • 2021-01-28 12:52

    I know, I'm super late to the party but, if you can live with data "sticking around" until the next app launch you can delete/clear data in application(_:didFinishLaunchingWithOptions).

    0 讨论(0)
  • 2021-01-28 12:54

    applicationWillTerminate: is basically never called and you should no longer rely on it.

    The app is not given any callback when it is killed so you can't do anything. You need to decide on a different approach based on the actual user requirement. This may involve encryption / not holding certain data on disk (only ever in memory) / etc...

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