Skip to content

fix(apple): end location requests when the prompt is answered or dismissed - #1583

Open
khb-works wants to merge 1 commit into
Baseflow:mainfrom
khb-works:fix/ios-location-request-completion
Open

khb-works wants to merge 1 commit into
Baseflow:mainfrom
khb-works:fix/ios-location-request-completion

Conversation

@khb-works

Copy link
Copy Markdown
Contributor

Location requests on iOS could return before the user answered the prompt, or never return:

Fixes #1152
Fixes #1457
Fixes #1035
Fixes #1261

As proposed in #1152 (comment), a location request now ends in one of three ways:

  • The delegate reports a status that differs from the one before the request. Callbacks that repeat the earlier status are ignored.
  • The prompt made the app resign active and the app is active again. The request returns the current status. This covers "Keep Only While Using", which doesn't change the status, and a prompt dismissed by locking the screen.
  • The app didn't resign active within 2 seconds, so no prompt is coming, as after "Allow Once". The request returns the current status.

Always is now marked as asked only when its prompt actually appeared. Before, the flag was set when requestAlwaysAuthorization was called, so after "Allow Once" a later Always request returned permanentlyDenied without asking.

Behavior changes to note:

  • After "Allow Once", requesting locationAlways returns denied after 2 seconds instead of right away.
  • The 2 second limit also applies to When In Use requests, which before waited only for the delegate.
  • The strategy reads the status from its CLLocationManager instance on iOS 14 and later, as the old didBecomeActive handler did, instead of the deprecated class method. This lets the tests inject a location manager.

Tests: LocationPermissionStrategyTests in the example's RunnerTests creates the strategy with a fake CLLocationManager, its own notification center and user defaults, and a short prompt timeout. It covers both choices in the upgrade prompt, the request without a prompt, asking again after it, the already-asked case, and When In Use granted or dismissed. The test target reads the private strategy header through HEADER_SEARCH_PATHS and looks the class up at runtime, since the plugin is linked into the app.

I also ran each case by hand on an iOS 26.5 simulator with this change, reinstalling the app before each case:

Steps request() returned
When In Use granted, request locationAlways, tap "Change to Always Allow" granted when tapped (13.9 s)
Same, tap "Keep Only While Using" permanentlyDenied when tapped (8.0 s). A second request returns permanentlyDenied in 6 ms.
"Allow Once", then request locationAlways denied after 2.1 s, with no prompt
After that, restart the app, grant When In Use again and request locationAlways The upgrade prompt appears, and granted when tapped
Request locationWhenInUse, lock the screen while the prompt is showing denied when the screen locks (8.8 s). After unlocking, the next request shows the prompt again.

I haven't tested on a physical device or on iOS versions other than 26.5. CI doesn't run the example's RunnerTests, so I ran them locally (8 tests pass), along with dart format, flutter analyze and the example release build with the release flavor selected.

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.
  • I ran dart format . and committed any changes.
  • I ran flutter analyze and fixed any errors.
  • This PR changes exactly one package
  • No permission integer was renumbered or reused, and the channel name is unchanged

@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.42%. Comparing base (0241e81) to head (07050aa).
⚠️ Report is 1 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (0241e81) and HEAD (07050aa). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (0241e81) HEAD (07050aa)
unittests 2 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1583       +/-   ##
===========================================
- Coverage   89.84%   71.42%   -18.42%     
===========================================
  Files           7        1        -6     
  Lines         128       35       -93     
===========================================
- Hits          115       25       -90     
+ Misses         13       10        -3     
Flag Coverage Δ
unittests 71.42% <ø> (-18.42%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment