android – React native如何每隔x分钟从api获取一次
作者:互联网
我想在android上每隔x分钟运行一次fetch(使用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本机处理程序可能?).我只发现了一个组件,但是对于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-android 来源: https://codeday.me/bug/20190713/1453240.html