flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

How to handle situation if user chose "Allow Only Once" ?

Open nhlhelen opened this issue 3 years ago • 6 comments

Hi all, I would like to request permission for "location always" in my app. I first request permission for "location while in use", then if it's granted, I'll request "location always".

However, in iOS 15, if the user chose "Allow Only Once" for "location while in use" permission, the permission status returns granted and the request for "location always" is stuck. I suspect the app could not request for "location always" when "only once" permission is granted. Now my app is stuck at the black loading screen. How could I detect if the user chose "Allow only once" option? And how could I request for "location always" permission?

The flow below works fine if the user chose "location when in use", it just didn't work if the user chose "allow only once", many thanks!

    final locationWhenInUseStatus = await Permission.locationWhenInUse.request();
    print("Location when in use status: $locationWhenInUseStatus");
    if (locationWhenInUseStatus.isGranted) {
      print("Location when in use is granted");
      var locationAlwaysStatus = await Permission.locationAlways.request();
      print("After requesting location always");

      if (!locationAlwaysStatus.isGranted) {
        print("Location always is denied");
        bool res = await openAppSettings();
      }
      
    }
    if (!locationWhenInUseStatus.isGranted) {
      print("Location when in use is not granted");
    }

nhlhelen avatar Mar 02 '22 06:03 nhlhelen

Hi @nhlhelen,

Seems like you are handling it the correct way, I am not familiar with this particular behaviour and will look into it. I will get back to you afterwards.

mvanbeusekom avatar Mar 02 '22 07:03 mvanbeusekom

@mvanbeusekom Thanks for the prompt reply! Hope to hear from you soon.

nhlhelen avatar Mar 02 '22 07:03 nhlhelen

Hello, I got same problem here. If user select allow once when app is requesting location permission for location always permission(readme says if you want to request location always, you should request locationWhileInUse permission first), await Permission.locationalways.request() not showing any dialogs for location always permission. Then if i call await Permission.locationalways.request() again, I got ERROR_ALREADY_REQUESTING_PERMISSIONS . Is there any way to check if location permission is allow once?

choi-seung-min avatar Mar 23 '22 09:03 choi-seung-min

@choi-seung-min I have the same issue too @mvanbeusekom Any update on this?

nhlhelen avatar Apr 28 '22 04:04 nhlhelen

I have this same issue. I'm happy to help fix it if someone is not already on it.

cspensky avatar May 06 '22 18:05 cspensky

same here

santa112358 avatar May 15 '22 15:05 santa112358

same here

mfaizanfalcon avatar Nov 14 '22 09:11 mfaizanfalcon

I'm also having this issue.

kvenn avatar Jan 03 '23 19:01 kvenn

Same issue how can we achieve this?

aea91 avatar Jan 14 '23 18:01 aea91

I'd like to keep this issue open. Just ran into the same issue

ublanke avatar Mar 13 '23 09:03 ublanke

I "solved" it by making the calls non-blocking. It might not work for every scenario.

instead of status = await Permission.locationAlways.request(); --> Permission.locationAlways.request();

It's not ideal, as I'd like to store the status, but as long as we can't handle this case and the call ends up blocking forever, there is nothing else to do.

Hope this gets fixed.

ublanke avatar Mar 13 '23 09:03 ublanke

any updates? Or any workarounds available?

typexy avatar Jun 25 '23 14:06 typexy

I have fixed it already, waiting for review

https://github.com/Baseflow/flutter-permission-handler/pull/1028

yerkejs avatar Jun 30 '23 11:06 yerkejs

@mvanbeusekom I see this issue on the latest version (11.3.1).

When user select "Allow Once" I call: await Permission.locationAlways.request();

But nothing is happening.

WUKS87 avatar Apr 04 '24 19:04 WUKS87