最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Flutter Geolocator: App is accessing GPS even after location stream is cancelled on iOS - Stack Overflow

programmeradmin5浏览0评论

Geolocator (13.0.2) is used to get location updates on iOS. Background mode is also used to get stream of coordinates even when app is in background. It is noticed that when app goes in background mode and come back again foreground mode, then even after cancelling position stream, app is still accessing the GPS. And this is confirmed by location icon shown in status bar of iPhone. However, app does not receive any location coordinates after cancelling the stream but that is draining the battery a lot.

StreamSubscription<dynamic>? _locationStream;

  void startLocationStream() {
    _locationStream = Geolocator.getPositionStream(
      locationSettings: AppleSettings(
    accuracy: LocationAccuracy.best,
    allowBackgroundLocationUpdates: true,
  ),
    ).listen(coordinateLogic);
  }

void stopLocationStream() {
 _locationStream?.cancel().then((_) {
      _locationStream = null;
    });
}

发布评论

评论列表(0)

  1. 暂无评论