-
-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Crash on permission denied - Release IOS only #1631
Comments
In the meantime, I was able to resolve the issue. It's a bit vague, but the problem was that I refactored this code into separate functions that caused the error. I'm not 100% sure, but it seems like the likely cause of the crash is that iOS release builds handle method calls differently with optimizations enabled. When the permission request is in a separate function, the compiler might optimize it in a way that affects the timing of the permission dialog presentation. So this code works fine // Example from package homepage
import 'package:geolocator/geolocator.dart';
Future<Position> _determinePosition() async {
bool serviceEnabled;
LocationPermission permission;
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Location permissions are denied');
}
}
if (permission == LocationPermission.deniedForever) {
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}
return await Geolocator.getCurrentPosition();
} But this code crashes // Example from package homepage
import 'package:geolocator/geolocator.dart';
Future<Position> _determinePosition() async {
bool serviceEnabled;
LocationPermission permission;
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}
// Separate function
checkAndRequestPermission();
if (permission == LocationPermission.deniedForever) {
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}
return await Geolocator.getCurrentPosition();
}
Future<void> checkAndRequestPermission() {
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Location permissions are denied');
}
}
} I had the same issue with the mobile_scanner package. This was solved by using the permission_handler to handle the camera permission request as it is baked into the mobile scanner code and couldn't be fixed. Hope anyone can give some more conclusive insights! 🙏 |
Please check the following before submitting a new issue.
Please select affected platform(s)
Steps to reproduce
The only thing I do differently is throwing an error and wrapping it with a try-catch instead of returning a Future.error. I tried to debug but it doesn't throw any error messages that I could tell.
Expected results
Don't crash on denying location permission (IOS, signed release build only)
Actual results
Crashes on denying location permission (IOS, signed release build only). Once denied, the app crashes every time the determinePosition function is called.
Code sample
Code sample
Screenshots or video
Screenshots or video demonstration
[Upload media here]
Version
13.0.2
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: