flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

[PermissionRequestInProgressException] Handling PermissionRequestInProgressException on iOS

Open kuhnroyal opened this issue 4 years ago • 16 comments

🐛 Bug Report

On iOS, when the app goes to background while the permission dialog is showing (due to pressing power button or display timeout, usually for 30+ seconds or so) and the phone is activated again, the permission dialog is gone. Afterwards it is not possible to request a permission again because it will always throw PermissionRequestInProgressException.

Expected behavior

The plugin should detect this case and ensure that the permission can be requested again. Somehow the confirmationHandler needs to be cleaned up here: https://github.com/Baseflow/flutter-geolocator/blob/master/geolocator/ios/Classes/Handlers/PermissionHandler.m#L37

Reproduction steps

  1. Make a call that requests the permission so that the dialog is showing (Geolocator.getCurrentPosition())
  2. Press the power button and let it sleep for 30+ seconds so that the app goes fully to background
  3. Wake the phone again, the dialog should be gone
  4. Repeat 1.

Version: 6.1.4

Platform:

  • [x] :iphone: iOS
  • [ ] :robot: Android

kuhnroyal avatar Nov 05 '20 13:11 kuhnroyal

Hi @kuhnroyal

Thanks for filling this issue. I was able to reproduce it.

If you would like, I think Baseflow would love to see your PR!

flutter doctor -v
[✓] Flutter (Channel master, 1.25.0-5.0.pre.141, on macOS 11.0.1 20B50 darwin-x64, locale nl-NL)
    • Flutter version 1.25.0-5.0.pre.141 at /Users/sempakonka/Documents/flutter
    • Framework revision 36bed2b4c3 (13 hours ago), 2020-12-09 20:13:04 -0500
    • Engine revision 8518a5bbe6
    • Dart version 2.12.0 (build 2.12.0-135.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/sempakonka/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.2, Build version 12B45b
    • CocoaPods version 1.10.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] Connected device (2 available)
    • iPhone van Sem (mobile) • 56ce8bf3d3e66ff2612301f221c7feb0a8acac2d • ios            • iOS 14.2
    • Chrome (web)            • chrome                                   • web-javascript • Google Chrome 87.0.4280.88


Sempakonka avatar Dec 10 '20 13:12 Sempakonka

I can't reproduce the issue on iOS14+, is this still an issue @kuhnroyal ?

florissmit1 avatar Apr 15 '21 13:04 florissmit1

I will try to test this again next week.

kuhnroyal avatar Apr 15 '21 14:04 kuhnroyal

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

no-response[bot] avatar Apr 30 '21 07:04 no-response[bot]

Sorry for the late reply, it seems the issue no longer occurs. Not sure what exactly fixed this, maybe the library is not allowing the app to go in background now.

kuhnroyal avatar Jul 06 '21 15:07 kuhnroyal

Re-opening this issue as @FelipeAndresLopez confirmed the issue is still occurring on recent versions of iOS.

mvanbeusekom avatar Aug 23 '21 16:08 mvanbeusekom

Still happening as of now.

Frostlight avatar Aug 23 '22 17:08 Frostlight

I'm still having this issue in ios 16.2, any idea how to fix this? was there an option to cancel when get this exception PermissionRequestInProgressException ?

frendcarlo avatar Feb 01 '23 12:02 frendcarlo

@frendcarlo yes we need to comment the native ios code inside plugin. open the file PermissionHandler.m and comment the return in lineno. 57 / (open the project in xcode and search the string "A request for location permissions is already running, please wait for it to complete before doing another request." and comment the return in lineno. 57) Screenshot 2023-02-13 at 3 26 09 PM

Abisheik-IAN avatar Feb 13 '23 09:02 Abisheik-IAN

Is there any updates? We have also the same issue.

SShayashi avatar Jun 26 '23 09:06 SShayashi

I do not know why, but this event did not occur when launching the example app from Xcode instead of from Android Studio.

SShayashi avatar Aug 15 '23 07:08 SShayashi

Currently, the policy is not to request again if the authorization request process is already running. https://github.com/Baseflow/flutter-geolocator/blob/c7dffa16311f5caf6ee3e48733be219183be9cf3/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m#L46

However, considering the case where the location authentication on the iOS side does not return, the following option is better:

  • Cancel the request already made and make a new request.
  • Set a timeout.

SShayashi avatar Aug 15 '23 07:08 SShayashi

I've tested the following on iOS 16.6 en it seems to work as expected:

Run example app; request a permission like camera; click the power button to switch off the screen; click the power button to switch on the screen( wait 30 + seconds); Log into your iPhone; The Alert reopens. (multiple times)

If this issue still occurs please inform us about detailed steps to reproduce and probably OS version.

But there are multiple issues regarding the PermissionRequestInProgressException. I've reproduced it before only on a Simulator.

Kind regards,

TimHoogstrate avatar Aug 24 '23 09:08 TimHoogstrate

I've reproduced it with location permissions indeed. I'll label it as a bug. However, I'm not sure if it is a bug from the plugin. Related to: https://github.com/Baseflow/flutter-permission-handler/issues/783

Kind regards,

TimHoogstrate avatar Aug 24 '23 09:08 TimHoogstrate

Commenting here to give #1217 some more exposure. This PR might fix the bug mentioned.

JeroenWeener avatar Sep 06 '23 07:09 JeroenWeener

This still happens, has it been fixed yet?

ThienUKPC avatar Dec 01 '23 07:12 ThienUKPC