Pet*_*nek 6 background ios flutter
我想在我的 Flutter 应用程序中实现某种后台作业/检查,但我注意到 iOS 上有这种奇怪的行为。
当我启动这个计时器并且仍在应用程序中时,一切正常,但是当我从应用程序返回主屏幕时,此回调执行五次然后停止。另一方面,在 Android 上,即使我在主屏幕上,它也会一直运行。
我在 info.plist 中添加了这个“权限”,但经过几次尝试后它仍然停止。
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
<string>remote-notification</string>
</array>
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个包(https://pub.dev/packages/workmanager),但对我不起作用。
这是我应该执行的函数
Timer.periodic(const Duration(seconds: 30), (_) async {
var parkingLots = await DataService().getFreePlaces();
if (parkingLots[parkingLotId] == 0) {
print("full");
} else {
print("job is running");
}
print(parkingLots[parkingLotId]);
});
Run Code Online (Sandbox Code Playgroud)
基本上,它应该每 30 秒检查停车场是否有一些空闲位置,如果没有,它应该向用户发送通知。
您知道如何使这项工作有效吗?或者您有什么建议如何做到这一点?
谢谢
| 归档时间: |
|
| 查看次数: |
846 次 |
| 最近记录: |