I have an iOS app developed on Flutter and I am stuck at the allow to access location step. I have the permission_handler: ^11.3.1 included in my .yaml file. I have added the following keys in my Info.plist
`<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location when in use</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Always and when in use!</string>
<key>NSLocationUsageDescription</key>
<string>Older devices need location.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Can I have location always?</string>`
This is my code for the page and button to ask for location access and proceed to the next step
Future<void> _checkLocationPermission() async {
// Request location permission using permission_handler
print('Requesting location permission...');
PermissionStatus permissionStatus = await Permission.locationWhenInUse.request();
print('Location permission status: $permissionStatus');
if (permissionStatus.isGranted) {
print('Location permission granted');
// Update the onboarding step in Firestore
User? user = auth.currentUser;
if (user != null) {
await firestore.collection('users').doc(user.uid).update({
'accessLocationAllowed': true,
});
print('Location access allowed updated in Firestore');
// Navigate to the next onboarding step
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const AllowNotificationsPage()),
);
}
} else if (permissionStatus.isPermanentlyDenied) {
print('Location permission permanently denied. Opening app settings.');
openAppSettings();
}
}
Whenever I click the button, it prints out
flutter: Location permission status: PermissionStatus.permanentlyDenied
flutter: Location permission permanently denied. Opening app settings.
Then I go to settings and have no options to allow for location to get access. I know it’s not Firebase messaging problem because I did the same for the notification permission and it worked (pop up and I can say allow or if I choose Don’t allow I am directed to Settings) but for some reasons it just immediately set the location permission to permanentlyDenied without pop up or any way for me to change it in the settings. This is what the setting page looks like
I have reset the content and settings on the stimulator but it still doesn’t work. This is my first app to Flutter so I really don’t know if I am missing something very obvious but I have tried everything I can find or think of. I have been at this for days and I really don’t know what’s causing the problem. Any hints or suggestion would be so so appreciated.