'IOS temporarily save data during app background refresh

I am building an app where we can record videos but it requires recording certain events due to which the app is closed and when the app is opened again , all the data is lost. Tiktok is using a similar approach where they save the data temporarily on the device storage and shows an alert when the app is opened again. Cant find the solution of what they are using to save data temporarily on device. This is how they are doing it - tiktok method



Solution 1:[1]

The question isn't clear to me. But I assume that you want to record something and get back at the time of relaunching the application.

The best way you can do:

First, continue recording until app goes to the background

Second, in appDidEnterBackground

a) please save the file to a unique name in the document directory/temp directory with a unique name. The second one is the best place to do. Then save the filename to the userdefaults.

or

b) Instead of doing the file save, save the Data to the userdefaults.

Third, in didBecomeActive

a) For 2a, if there is a name, try to fetch the file from the directory.

b) For 2b, if there is data available in userdefaults, try to show an alert that there is something in the userdefaults.

You have thousands of answers in StackOverflow for all of those steps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ankur Lahiry