【问题标题】:Flutter App unable to access internet when in backgroundFlutter App 在后台无法访问互联网
【发布时间】:2021-04-22 15:09:59
【问题描述】:

我正在构建一个出租车应用程序(在 Android 和 IOS 上运行),需要使用计时器每 10 秒后将驱动程序位置更新到数据库中。
地理定位器包会不断准确地选择驾驶员当前位置,然后将其发送到实时数据库。

问题
仅当应用程序处于前台时,更新才能正常运行
应用程序进入后台或最小化后,我会收到“无互联网或 Wifi”错误,因此不会更新位置。
计时器继续在后台运行,但由于没有互联网,它无法更新数据库。

问题
如何确保应用在后台接收互联网,以便不断更新驱动程序位置?

定时器

Timer timer;
timer = Timer.periodic(Pallete.refreshTime, (timer) {
  _getLocation();
});

_getLocation

Future<void> _getLocation() async {
    await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high).then((value) =>{
      postLocation( context,'${value.latitude},${value.longitude}')
    });
}

postLocation(BuildContext context,String location){
    final myCubit = BlocProvider.of<DriveractivejobCubit>(context);
    myCubit.updateLocation(context, location);
}

【问题讨论】:

  • 这对你有帮助吗stackoverflow.com/a/60441628/14231239
  • 我认为这会有所帮助,谢谢。 ...您建议我删除这个问题还是应该如何将人们重定向到其他链接?

标签: flutter dart geolocation background-process


【解决方案1】:

可以在此链接上找到关于为什么会发生这种情况的更好解释。
它还解释了我们必须实现这一目标的几个选项。
感谢@dm_tr
stackoverflow.com/a/60441628/14231239

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2020-12-16
    • 2014-11-16
    相关资源
    最近更新 更多