简体   繁体   English

IOS app后台刷新时临时保存数据

[英]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. Tiktok 正在使用类似的方法,他们将数据临时保存在设备存储中,并在再次打开应用程序时显示警报。 Cant find the solution of what they are using to save data temporarily on device.找不到他们用来在设备上临时保存数据的解决方案。 This is how they are doing it - tiktok method他们就是这样做的-tiktok方法

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二、在appDidEnterBackground

a) please save the file to a unique name in the document directory/temp directory with a unique name. a) 请将文件以唯一名称保存在文档目录/临时目录中的唯一名称。 The second one is the best place to do.第二个是最好的地方。 Then save the filename to the userdefaults.然后将文件名保存到 userdefaults。

or或者

b) Instead of doing the file save, save the Data to the userdefaults. b) 不保存文件,而是将Data保存到 userdefaults。

Third, in didBecomeActive三、在didBecomeActive

a) For 2a, if there is a name, try to fetch the file from the directory. a) 对于 2a,如果有名称,请尝试从目录中获取文件。

b) For 2b, if there is data available in userdefaults, try to show an alert that there is something in the userdefaults. b) 对于 2b,如果 userdefaults 中有可用数据,请尝试显示 userdefaults 中有内容的警报。

You have thousands of answers in StackOverflow for all of those steps.对于所有这些步骤,您在 StackOverflow 中有数千个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM