首页 > 解决方案 > 当应用程序在后台时,IOS会阻止位置监听

问题描述

我的应用程序使用包geolocator: ^5.1.5 我编码功能监听用户位置,当他靠近我通知他的点时,它工作正常但是当应用程序在屏幕上打开但当按下主页并将应用程序置于后台时它什么都不推送,但当恢复应用程序时应用程序推送有关位置的通知。

我的功能位置监听器

//? Listen option
var locationOptions = LocationOptions(
accuracy: LocationAccuracy.best, distanceFilter: 50);
//? listen
locationStreamListener =
    Geolocator().getPositionStream(locationOptions).listen(
  (Position position) async {
    //? latLng of current location
    LatLng currentLatlng = LatLng(position.latitude, position.longitude);

    if(currentLatlng == myPointLocation){
        LocalNotificationsHelper(context).show(
         title: 'reach point',
         body:
         'there is action you have to do.',
         id: list.intId,
         payload: list.id);

    }

});

这是我在 ios 设备上的应用权限

在此处输入图像描述

这些是 info.plist 值

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>

我的应用程序 x 代码功能
在此处输入图像描述

标签: iosflutter

解决方案


推荐阅读