flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

[Question]: iOS keeps requesting location data while the app is in use

Open lowrt opened this issue 1 year ago • 0 comments

Please check the following before submitting a new issue.

Please select for which platform(s) you need help

  • [ ] Android
  • [X] iOS
  • [ ] Linux
  • [ ] macOS
  • [ ] Web
  • [ ] Windows

Your question

I don’t know why the “during app use” permission keeps accessing location data.

If you adjust the permanent permissions, the positioning data will not be refreshed all the time.

https://github.com/Baseflow/flutter-geolocator/assets/37591855/f93514ad-b0ec-4c61-b129-466cba1fdb9a

main.dart

void startPositionStream() {
    if (positionStreamSubscription == null) {
      final positionStream = geolocatorPlatform.getPositionStream(
        locationSettings: Platform.isAndroid
            ? AndroidSettings(
                accuracy: LocationAccuracy.medium,
                distanceFilter: 500,
                forceLocationManager: false,
                intervalDuration: const Duration(minutes: 5),
                //(Optional) Set foreground notification config to keep the app alive
                //when going to the background
                foregroundNotificationConfig: const ForegroundNotificationConfig(
                ///
                ),
              )
            : AppleSettings(
                accuracy: LocationAccuracy.low,
                activityType: ActivityType.other,
                distanceFilter: 500,
                timeLimit: const Duration(minutes: 5),
                pauseLocationUpdatesAutomatically: true,
                // Only set to true if our app will be started up in the background.
                showBackgroundLocationIndicator: false,
                allowBackgroundLocationUpdates: true,
              ),
      );
      positionStreamSubscription = positionStream.handleError((error) {
        positionStreamSubscription?.cancel();
        positionStreamSubscription = null;
      }).listen((Position? position) async {
        if (position != null) {
          String? lat = position.latitude.toStringAsFixed(4);
          String? lon = position.longitude.toStringAsFixed(4);
          String? coordinate = '$lat,$lon';
          messaging.getToken().then((value) {
            ///
            );
          });
        }
      });
    }
  }

Version

12.0.0

lowrt avatar Jun 22 '24 14:06 lowrt