Baseflow / flutter-geolocator

Android and iOS Geolocation plugin for Flutter
https://baseflow.com/
MIT License
1.24k stars 653 forks source link

[PermissionRequestInProgressException] Handling PermissionRequestInProgressException on iOS #581

Open kuhnroyal opened 3 years ago

kuhnroyal commented 3 years ago

🐛 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:

Sempakonka commented 3 years ago

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 ```
florissmit1 commented 3 years ago

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

kuhnroyal commented 3 years ago

I will try to test this again next week.

no-response[bot] commented 3 years ago

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.

kuhnroyal commented 3 years ago

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.

mvanbeusekom commented 3 years ago

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

Frostlight commented 2 years ago

Still happening as of now.

frendcarlo commented 1 year ago

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 ?

Abisheik-IAN commented 1 year ago

@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
SShayashi commented 1 year ago

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

SShayashi commented 1 year ago

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

SShayashi commented 1 year ago

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:

TimHoogstrate commented 1 year ago

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 commented 1 year ago

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,

JeroenWeener commented 1 year ago

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

ThienUKPC commented 10 months ago

This still happens, has it been fixed yet?