我想在 android 上每 x 分钟运行一次获取(使用 React native)
function getMoviesFromApiAsync() {
return fetch('https://facebook.github.io/react-native/movies.json').then((response) => response.json()) .then((responseJson) => {
return responseJson.movies; }) .catch((error) => { console.error(error); });
}
我使用了 documentaion 中的示例,因为我仍然不确定我将如何进行这种提取。
我不确定我应该如何开始这个(也许制作一个 android native 处理程序?)。我只找到了一个组件,但它适用于 ios iOS Background Fetch API Implementation
最佳答案
componentDidMount(){
this.timer = setInterval(()=> this.getMovies(), 1000)
}
async getMovies(){
fetch('https://facebook.github.io/react-native/movies.json', {method: "GET"})
.then((response) => response.json())
.then((responseData) =>
{
//set your data here
console.log(responseData);
})
.catch((error) => {
console.error(error);
});
}
关于android - React native 如何每 x 分钟从 api 中获取一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41238609/