Delete data when app is killed in the background.

前端 未结 3 708
误落风尘
误落风尘 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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.

提交回复
热议问题