flutter-geolocator
flutter-geolocator copied to clipboard
[Question]: iOS keeps requesting location data while the app is in use
Please check the following before submitting a new issue.
- [X] I have searched the existing issues.
- [X] I have carefully read the documentation.
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