Repository navigation
Conversation
Author
|
The CI failures are unrelated to this change. |
mansurrrr
marked this pull request as ready for review
November 16, 2026 07:45
9 of 10 tasks
mansurrrr
force-pushed
the
fix/ios-request-result-main-queue
branch
from
December 2, 2026 07:03
c6ea66d to
b45a9cc
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1587 +/- ##
=======================================
Coverage 71.42% 71.42%
=======================================
Files 1 1
Lines 35 35
=======================================
Hits 25 25
Misses 10 10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
requestPermissionson iOS sometimes fails withERROR_ALREADY_REQUESTING_PERMISSIONSwhen it is called right after a previous request has completed.Cause.
PermissionHandlerPlugintracks the in-flight request with_methodResultand rejects a new request while it is set. Some strategies call their completion handler on a background queue. For example,NotificationPermissionStrategycallscompletionHandler(PermissionStatusPermanentlyDenied)directly from therequestAuthorizationWithOptions:callback when the user denies. The plugin then delivers the result to Dart and clears_methodResulton that background queue. Dart can receive the result and send the nextrequestPermissionscall before_methodResult = nilhas run, so the main thread still sees a pending request and rejects the call.We see this in production after a notification denial followed immediately by an App Tracking Transparency request:
We reproduced the failure by adding a short delay before
_methodResult = nil: the Dart side has already received the result, yet the next request fails.Change. In
PermissionHandlerPlugin.m, therequestPermissionscompletion and error handlers now run on the main queue. They run inline when already on the main thread. Clearing_methodResultand checking it for the next request now happen on the same thread, in order. This fixes all strategies in one place rather than in each one.Testing. No unit tests exist for
permission_handler_apple. Verified on an iPhone 16 Pro running iOS 27.2, with a 1 s delay injected before_methodResult = nilto make the race deterministic:ERROR_ALREADY_REQUESTING_PERMISSIONS, and the ATT prompt is not shown._methodResultis cleared, and the ATT prompt is shown.Related: #1511 addresses a different path to the same error (state not reset when the app goes to the background) and does not touch this race.
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.///). (Objective-C only; no public API change.)main.dart format .and committed any changes. (No Dart changes.)flutter analyzeand fixed any errors. (No Dart changes.)