Skip to content

permission_handler_watchos: locationAlways reads denied until it is asked for - #44

Merged
MAUstaoglu merged 2 commits into
flutterwatch:mainfrom
iamoguzhanarslantas:permission-handler-watchos-always-status
Nov 20, 2026
Merged

MAUstaoglu merged 2 commits into
flutterwatch:mainfrom
iamoguzhanarslantas:permission-handler-watchos-always-status

Conversation

@iamoguzhanarslantas

@iamoguzhanarslantas iamoguzhanarslantas commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

permission_handler_apple 9.6.4 fixed Permission.locationAlways.status answering permanentlyDenied while "When In Use" is granted and "Always" has not been requested yet: it now answers denied, so the app can still request it. permission_handler_watchos was ported from 9.6.2 and still gave the old answer. This mirrors the fix.

Since apps now reach that request, it also answers an "always" request that watchOS shows no prompt for (from the review). watchOS shows the "always" prompt once. If other code in the app asked for "always" before, or the prompt was shown before a reinstall that kept location but not this package's flag, the request got no delegate call and no return to active, and waited forever. Now, if the app has not resigned active two seconds after the request, the status then is the answer.

Not verified on a physical Apple Watch. Everything below was checked on the watchOS 27.0 Simulator and on the host.

The weekly upstream job compares permission_handler, still 13.0.2, so a new permission_handler_apple does not show up there. This came from comparing the port's source, 9.6.2, with 9.6.5 on pub.dev.

What permission_handler_apple 9.6.3 to 9.6.5 change for this package:

  • 9.6.4, locationAlways status: ported here. The status check reads the NSUserDefaults flag that the "always" request already sets, so once "always" was asked for and kept at "while using" it still answers permanentlyDenied, as upstream does. The check sits under PERMISSION_LOCATION, like the flag: an app with NSLocationWhenInUseUsageDescription alone still has no NSUserDefaults reference and no "always" request.
  • 9.6.4, notification and critical-alert status on iOS 27: nothing to port. Upstream stopped waiting on a semaphore on the main thread; the watch strategies already read getNotificationSettingsWithCompletionHandler: asynchronously.
  • 9.6.5, Permission.phone service status answered twice: nothing to port. phone answers as a permission watchOS does not have.
  • 9.6.3, PERMISSION_HANDLER_INFO_PLIST in the SwiftPM manifest: nothing to port; flutter-watchos applies defines instead.
  • Upstream's example lib/ is unchanged since 9.6.3. 9.6.5 adds an iOS XCTest for the notification change only.

Changes:

  • phw_location.m: the status check. In requestAlways, a check two seconds after the request answers with the status if the app has not resigned active and nothing has answered, under the _answers guard of the delayed re-read.
  • example/integration_test/permission_handler_test.dart: a new case, "always" can still be asked for after "when in use". It and the case for "always" before "when in use" each need location in a given state, and skip with the simctl command otherwise. The file header and the example README say to set location before a run, since the Simulator keeps the answer across installs.
  • CHANGELOG (0.0.1 is unpublished, so its entry gets a bullet), README's behaviour table, PORTING_REPORT (its Source line now says the port was compared through 9.6.5, without the local path).

Verified

On the watchOS 27.0 Simulator (Apple Watch Series 12, 46 mm), with flutter-watchos 0.1.2:

  • With location reset: 5 passed and the new case skipped. With location allowed "while using": 5 passed and the case for "always" before "when in use" skipped. With main's phw_location.m put back, the new case fails (Expected: PermissionStatus.denied, Actual: PermissionStatus.permanentlyDenied).
  • With scratch tests, not committed, and location allowed "while using":
    • After reset location, the "always" prompt came up. Left up for 32 s and answered "Keep Only While Using": permanentlyDenied, the status then permanentlyDenied, and a second request permanentlyDenied without a prompt. Left up for 17 s and answered "Change to Always Allow": granted.
    • After a reinstall that kept location, watchOS showed no "always" prompt. With 77e6ada the request never completed (the test gave up after 25 s); with b030bd6 it answered permanentlyDenied after 2.1 s, and the status then read permanentlyDenied.

On the host:

  • phw_location.m compiled for the watchOS Simulator with the marker and PERMISSION_LOCATION_WHENINUSE alone has no NSUserDefaults or requestAlwaysAuthorization reference (nm -u) and no askedAlways key. With PERMISSION_LOCATION, or with no -D, it has them. None of these builds warns with -Wall -Wextra.
  • flutter analyze lib test and the 15 host tests, flutter analyze of the example's integration_test/, every tool/ check, dart format as CI runs it, pub publish --dry-run, and tool/check_native_sources.sh with Xcode 27.2 (phw_location.m with no -D, with the marker and every macro, with the marker alone, and with the marker and each macro alone, for a watch and the Simulator): clean.

Not verified

  • A physical Apple Watch.
  • Xcode 26: only Xcode 27.2 is installed here. The native job covers it.

🤖 Generated with Claude Code

permission_handler_apple 9.6.4 answers Permission.locationAlways.status
with denied, not permanentlyDenied, while "when in use" is granted and
"always" has not been asked for, so an app can still ask for it. The
watch strategy, ported from 9.6.2, still gave the old answer. Its status
check now reads the flag the "always" request already sets, compiled in
with PERMISSION_LOCATION only, as the flag is.

The example's integration test gets a case for it, meaningful with
location allowed "while using" beforehand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MAUstaoglu MAUstaoglu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @iamoguzhanarslantas, this is a clean port of permission_handler_apple 9.6.4. I checked it against upstream's #1577. The status table now matches iOS in every state: with "when in use" granted, locationAlways reads denied until asked and permanentlyDenied after. The new read stays under PERMISSION_LOCATION, so the #19 opt-in holds, and the flag is read and written on the main queue only. The CHANGELOG line under the unpublished 0.0.1 is right.

One thing I would like in this PR before it merges, because this change is what makes it reachable:

  1. Now that apps will request "always" after reading denied, a request can wait forever if watchOS does not show the prompt. requestAlways is answered only by the delegate or by the app resigning active and coming back, and observeActive ignores a become-active that had no resign before it. That could happen when something else in the app already asked for "always", or on the Simulator after a reinstall, where location is kept but NSUserDefaults is not. Before this change the status read permanentlyDenied there, so apps did not ask. I have read this in the code, not seen it on a watch. Could requestAlways answer with the current status if the app has not resigned active within a second or two? That is the same pattern as the existing delayed re-read, with the same _answers guard.

Two smaller things, here or in a later PR, as you prefer:

  1. The two location cases in the integration test return early and report a pass when their precondition is missing. Could they use markTestSkipped with the simctl hint, as the network_info start test does?
  2. In PORTING_REPORT, could the Source line note that the port was compared through 9.6.5, and drop the local .pub-cache home path (that line predates this PR)?

#42 and #43 are merged, thank you for both.

…prompt

watchOS shows the "always" prompt once. When it was shown before without
the askedAlways flag knowing, by other code in the app or before a
reinstall that kept location but not NSUserDefaults, a request gets
nothing back: no delegate call and no return to active, so it waited
forever. Now that locationAlways reads denied until it is asked for, apps
reach that request. If the app has not resigned active two seconds after
it, the status then is the answer, under the _answers guard the delayed
re-read uses.

The example's two location cases skip with a simctl hint instead of
passing when their precondition is missing, and the PORTING_REPORT's
Source line says the port was compared through 9.6.5, without the local
path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamoguzhanarslantas

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three are in b030bd6.

  1. requestAlways now arms a check after requestAlwaysAuthorization. If the app has not resigned active two seconds later and nothing has answered (the _answers guard of the delayed re-read), it answers with the status at that moment: permanentlyDenied while "when in use" stands, since the flag was set just before the request. The Simulator showed the case you describe: after a reinstall that kept location, watchOS put up no "always" prompt, and on 77e6ada the request never completed (a scratch test gave up after 25 s). With the change it answered permanentlyDenied after 2.1 s. A prompt that does come up is not cut short: left up for 32 s and 17 s, the request waited for the tap and answered permanentlyDenied for "Keep Only While Using" and granted for "Change to Always Allow" (xcrun simctl privacy … reset location brings the prompt back). If a watch took more than two seconds to put the prompt up, the request would answer before the wearer does; their answer still reaches CoreLocation, and the next status read sees it.
  2. Both location cases now call markTestSkipped with the simctl command. The Simulator keeps the location answer across installs, so the file header and the example README say to reset or grant it before a run. With it reset, 5 pass and the new case skips; with "while using", 5 pass and the "always" before "when in use" case skips.
  3. The Source line now reads "permission_handler_apple 9.6.2, compared through 9.6.5", without the path.

The CHANGELOG line and the PORTING_REPORT's design notes describe the new answer, and the PR description is updated to match. A local replay of CI is clean: analyze and the 15 host tests, every tool/ check, format, the publish dry run, and the native sources with Xcode 27.2.

@MAUstaoglu MAUstaoglu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @iamoguzhanarslantas, all three are in, and the trace holds up.

The hang is closed: every path into requestAlways either answers at once or arms the 2 s check. The check stands down on any answer (_answers) or a resign, so nothing answers twice or answers a later request. It runs on the main queue only, holds the strategy weakly, and the Dart _requesting guard is released on that path too. The answer it gives, permanentlyDenied, is what permission_handler_apple reports for "always" kept at "while using", and what the status reads afterwards. The new code sits under PERMISSION_LOCATION, so the #19 opt-in holds. The skipped cases and the Source line are as asked, and the CHANGELOG and PORTING_REPORT sentences match the code.

Nothing blocks. I'll merge this, and then look at one timing case myself on the Simulator before 0.1.0, so there's nothing to change here. Consider [Permission.locationWhenInUse, Permission.locationAlways].request() from a reset location. If the delegate answers the first request before the app becomes active again, and watchOS shows the second prompt without the app going active in between, no resign arrives. The check would then answer while the "always" prompt is still up. If that shows up, I'll make the check answer only while the app is active, and look again later otherwise. A slow watch that takes more than 2 s to show the prompt is the same case, and needs a physical watch to measure.

@MAUstaoglu
MAUstaoglu merged commit 40d16bf into flutterwatch:main Nov 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants