【发布时间】:2020-11-08 22:12:25
【问题描述】:
我正在尝试启动后台计时器。 我想运行代码,它也会在后台为 iOS 执行。
我使用 react-native-background-timer库。
但是当我最小化应用程序时,代码不会运行。 我在模拟器以及我的 IOS 设备(调试和发布)上运行该应用程序。 但是应用最小化后代码不运行。
我的代码:
var myTimer;
componentDidMount(): void {
const time = BackgroundTimer.setInterval(() => {
Geolocation.getCurrentPosition(
position => {
const location = JSON.stringify(position);
console.log(position.coords.latitude);
this.setState({
location,
latitude: position.coords.latitude,
longitude: position.coords.longitude
});
});
}
}
【问题讨论】:
标签: node.js react-native npm task background-task