You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace this paragraph with a short description of what issue this pull request (PR) solves and provide a description of the change. Consider including before/after screenshots.
List at least one fixed issue.
Pre-launch Checklist
I made sure the project builds.
I read the Contributor Guide and followed the process outlined there for submitting PRs.
I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is does not need version changes.
I updated CHANGELOG.md to add a description of the change.
I updated/added relevant documentation (doc comments with ///).
I rebased onto main.
I added new tests to check the change I am making, or this PR does not need tests.
I made sure all existing and new tests are passing.
guide-linhnv
changed the title
fix(iOS): resolve permission dialog hang when app goes to background
fix(iOS): resolve permission dialog hang when app goes to background. Issue: https://github.com/Baseflow/flutter-geolocator/issues/1518
Mar 12, 2026
This PR fixes issue #1518 where Geolocator.requestPermission() Future hangs indefinitely when the iOS app goes to background while the location permission dialog is
displayed.
Problem
On iOS, when the location permission dialog is showing and the user:
Locks their phone
Switches to another app
Triggers any action that backgrounds the app
iOS automatically dismisses the permission dialog without calling the CLLocationManagerDelegate callback. This causes:
The requestPermission() Future to never complete (hang forever)
Subsequent permission requests to fail with: "A request for location permissions is already running"
Root Cause
iOS's CLLocationManager delegate method locationManager:didChangeAuthorizationStatus: is not called when the permission dialog is dismissed due to app backgrounding.
The Flutter side keeps waiting for a response that will never arrive.
Solution
Added app lifecycle monitoring to detect when the app returns to foreground after being backgrounded during a permission request:
Register for UIApplicationDidBecomeActiveNotification when starting a permission request
Track permission request state with isWaitingForPermission flag
On app becoming active:
Wait 0.3s to allow any pending system callbacks to process
Check if still waiting for permission response
Resolve the callback with current authorization status
Proper cleanup of notification observers in both cleanUp and dealloc
Changes
PermissionHandler.m: Added lifecycle observer and handling logic (iOS only, wrapped in #if TARGET_OS_IOS)
Testing
Tested on iOS 17+ simulator and device
Verified permission dialog works normally when user makes a choice
Verified Future resolves correctly when app is backgrounded during dialog
Verified subsequent permission requests work after backgrounding
Verified no impact on macOS (changes are iOS-specific)
Breaking Changes
None. This is a bug fix that doesn't change any public API.
guide-linhnv
changed the title
fix(iOS): resolve permission dialog hang when app goes to background. Issue: https://github.com/Baseflow/flutter-geolocator/issues/1518
fix(iOS): resolve permission dialog hang when app goes to background.
Mar 12, 2026
Hi @mvanbeusekom,
Could you please help me review this PR?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace this paragraph with a short description of what issue this pull request (PR) solves and provide a description of the change. Consider including before/after screenshots.
List at least one fixed issue.
Pre-launch Checklist
pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is does not need version changes.CHANGELOG.mdto add a description of the change.///).main.dart format .and committed any changes.flutter analyzeand fixed any errors.