Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应本族语:如何在一段时间后提取,比如24小时?_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 反应本族语:如何在一段时间后提取,比如24小时?

Javascript 反应本族语:如何在一段时间后提取,比如24小时?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我想在24小时后取,这样用户就可以从应用程序中获得新的食谱。现在,我在屏幕渲染时调用它,但我希望它在一定时间后获取,例如24小时,我需要一个函数,即使在应用程序关闭时也计算时间。有办法做到这一点吗 异步函数getUserData(){ var userData=await firebase.firestore().doc(“配料/”+user.uid.get(); 变量标签=[] userData.data().components.forEach(component=>{ 标签.推送(配料.

我想在24小时后取,这样用户就可以从应用程序中获得新的食谱。现在,我在屏幕渲染时调用它,但我希望它在一定时间后获取,例如24小时,我需要一个函数,即使在应用程序关闭时也计算时间。有办法做到这一点吗

异步函数getUserData(){ var userData=await firebase.firestore().doc(“配料/”+user.uid.get(); 变量标签=[] userData.data().components.forEach(component=>{ 标签.推送(配料.标签) }) userData.data() SetUserComponents(标签) 获取配方(标签) } 函数获取配方(UserComponents){ 变量url=”https://europe-west3-cookingapp-b71aa.cloudfunctions.net/fetchRecipes?userIngredients=“+UserComponents.join(+)+”&idToken=“+user.idToken 获取(url{ 方法:“获取” }).then((response)=>response.json()) .然后((responseJson)=>{ responseJson=JSON.parse(responseJson) if(responseJson){ var newRecipes=[] 对于(变量i=0;i<3;i++){ const hit=responseJson.hits[Math.floor(Math.random()*responseJson.hits.length)] 常数newRecipe={ id:hit.recipe.uri, image:hit.recipe.image, 标签:hit.recipe.label, 时间:hit.recipe.totalTime, } newRecipes.unshift(newRecipe) } 设置加载(假); setUserRecipes(新配方) } 否则{ 控制台日志(“费勒”) } })
}检查react native background fetch:

我的建议是使用AsyncStorage将当前fetch执行的时间保存到存储中。然后在启动应用程序时,检查存储值并计算差异时间。如果它符合您的条件,则重新执行您的调用功能。

我在ios上使用expo,因此我没有xcode。是否有其他方法或它是否适用于expo?我不想用几分钟的时间来做这件事,就像每次0:00一个钟声敲响一样。我对世博会没有太多经验。一个想法可能是在您想要的时间安排推送通知,当单击通知时,您将获取您的数据。您可以使用ok,我也考虑过这一点。我想我会这样做的