flutter-permission-handler
flutter-permission-handler copied to clipboard
[Bug]: Permission.always.status returns permanentlyDenied even when can be requested
Please check the following before submitting a new issue.
- [X] I have searched the existing issues.
- [X] I have carefully read the documentation and verified I have added the required platform specific configuration.
Please select affected platform(s)
- [ ] Android
- [X] iOS
- [ ] Windows
Steps to reproduce
- request locationWhileInUse
- Choose 'Allow While Using App' on the ios device
- get status from location always permission
I already mentioned this issue here https://github.com/Baseflow/flutter-permission-handler/issues/1128. But since it's closed I decided to open another one. Maybe I am missing something again
Expected results
the permission status of the always location should be denied since it never was requested but can be requested
Actual results
the permission status is permantelyDenied. And therefore I have no way to check if I can request always permission or not
Code sample
Code sample
final locationWhenInUseStatus = await Permission.locationWhenInUse.request();
if (locationWhenInUseStatus.isPermantlyDenied) {
print("Can't request always permission");
} else {
var locationAlwaysStatus = await Permission.locationAlways.request();
// is never reached since 'Allow Only Once' and 'Allow While Using App' both return permantlyDenied
}
Screenshots or video
No response
Version
10.2.0
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E772610a darwin-arm64, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.2)
[✓] VS Code (version 1.81.1)
[✓] Connected device (4 available)
[✓] HTTP Host Availability
• No issues found!
Hi @Smibser thank you for opening a new issue.
I did some investigation and this does indeed look like a bug which we should investigate.
Recording of the bug in action: https://github.com/Baseflow/flutter-permission-handler/assets/9049645/a5622730-fbe8-4261-a934-a2fc8d8cf439
I came across something that may be related to this bug as well, around locationAlways
(on iOS). It seems that await Permission.locationAlways.request();
doesn't actually wait for the user's response, and returns right away (as the ask dialog is presented to the user, not as the user responds to the dialog).
I logged a separate issue over here: https://github.com/Baseflow/flutter-permission-handler/issues/1152.
I'm experiencing this too but for Permission.storage.request()
permission_handler: ^11.2.0
I encountered the same problem when using PermissionStatus permissionStatus = await Permission.photosAddOnly.request();
Is there any solution?
same issue on Permission.bluetooth
Same problem with Permission.photosAddOnly.request()
@Smibser The same issue I am facing but in a different way.
- Grant both permissions
While using the app
&Always Allow
- Then change the permission by Settings app from
Always
toAsk Next Time or When I Share
- After that, I can see a permission pop-up of
While using the app
but not forAlways allow
Same problem with Permission.photos.request()
, too.
Has anyone found a solution?
Actually for iOS if you are using PermissionHandler for permission handling. You need to specify the permissions in the info.plist file as well as in podFile.
Here is an example of podFile `post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
# You can remove unused permissions here
# for more information: https://github.com/BaseflowIT/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.calendar
'PERMISSION_EVENTS=1',
## dart: PermissionGroup.calendarFullAccess
'PERMISSION_EVENTS_FULL_ACCESS=1',
## dart: PermissionGroup.reminders
'PERMISSION_REMINDERS=1',
## dart: PermissionGroup.contacts
'PERMISSION_CONTACTS=1',
## dart: PermissionGroup.camera
'PERMISSION_CAMERA=1',
## dart: PermissionGroup.microphone
'PERMISSION_MICROPHONE=1',
## dart: PermissionGroup.speech
'PERMISSION_SPEECH_RECOGNIZER=1',
## dart: PermissionGroup.photos
'PERMISSION_PHOTOS=1',
## The 'PERMISSION_LOCATION' macro enables the `locationWhenInUse` and `locationAlways` permission. If
## the application only requires `locationWhenInUse`, only specify the `PERMISSION_LOCATION_WHENINUSE`
## macro.
##
## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
'PERMISSION_LOCATION=1',
'PERMISSION_LOCATION_WHENINUSE=0',
## dart: PermissionGroup.notification
'PERMISSION_NOTIFICATIONS=1',
## dart: PermissionGroup.mediaLibrary
'PERMISSION_MEDIA_LIBRARY=1',
## dart: PermissionGroup.sensors
'PERMISSION_SENSORS=1',
## dart: PermissionGroup.bluetooth
'PERMISSION_BLUETOOTH=1',
## dart: PermissionGroup.appTrackingTransparency
'PERMISSION_APP_TRACKING_TRANSPARENCY=1',
## dart: PermissionGroup.criticalAlerts
'PERMISSION_CRITICAL_ALERTS=1',
## dart: PermissionGroup.criticalAlerts
'PERMISSION_ASSISTANT=1',
]
end
end end`
Sadly for the locationAlways permission (iOS), the root cause seems to be that there is no way (on the native side) to make a distinction between the user having accepted the locationWhenInUse permission and user having dismiss the locationAlways permission.
I solve this issue by saving a boolean in shared preferences when we ask the always location for the first time. That way I can now that we already ask and now if the permission is not given, that means that the user dismissed it.