Baseflow / flutter-permission-handler

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
https://baseflow.com
MIT License
2.04k stars 850 forks source link

[Bug]: Permission.always.status returns permanentlyDenied even when can be requested #1145

Open Smibser opened 1 year ago

Smibser commented 1 year ago

Please check the following before submitting a new issue.

Please select affected platform(s)

Steps to reproduce

  1. request locationWhileInUse
  2. Choose 'Allow While Using App' on the ios device
  3. 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 ```dart 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 ```console [✓] 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! ```
JeroenWeener commented 1 year ago

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

jeffscaturro-aka commented 1 year ago

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.

MendleM commented 11 months ago

I'm experiencing this too but for Permission.storage.request()

levinx7512 commented 8 months ago

permission_handler: ^11.2.0

I encountered the same problem when using PermissionStatus permissionStatus = await Permission.photosAddOnly.request();

Is there any solution?

Justincyz commented 7 months ago

same issue on Permission.bluetooth

merliandrea commented 6 months ago

Same problem with Permission.photosAddOnly.request()

nayanAubie commented 6 months ago

@Smibser The same issue I am facing but in a different way.

FFelipeWNeo commented 5 months ago

Same problem with Permission.photos.request(), too. Has anyone found a solution?

mateendev3 commented 4 months ago

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`

Pierre-Monier commented 4 months ago

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.