Repository navigation
fix(ios): read notification permission status without blocking the main thread - #1573
Merged
mvanbeusekom merged 2 commits intoOct 23, 2026
Merged
Conversation
…in thread `NotificationPermissionStrategy` and `CriticalAlertsPermissionStrategy` waited for `getNotificationSettingsWithCompletionHandler:` with `dispatch_semaphore_wait(DISPATCH_TIME_FOREVER)` on the platform (main) thread. When the settings are delivered on the main queue (iOS 27) the wait never ends and the app freezes, typically on the launch screen. Following the approach of Baseflow#1100 for `checkServiceStatus`: - `PermissionStrategy` gains an optional asynchronous `checkPermissionStatus:completionHandler:`; every other strategy keeps its synchronous path. - `+[PermissionManager checkPermissionStatus:result:]` uses it when the strategy responds to the selector and calls `result` on the main queue. - Both strategies implement it on top of `getNotificationSettingsWithCompletionHandler:` without a semaphore and use the same asynchronous check in `requestPermission:`. The status mapping is unchanged. Adds a `RunnerTests` target to the example with a test that calls the plugin on the main thread and fails when the status is resolved synchronously. Fixes Baseflow#1420
mvanbeusekom
approved these changes
Oct 23, 2026
mvanbeusekom
left a comment
Member
There was a problem hiding this comment.
This looks great, thank you very much for this contribution.
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.
Fixes #1420
Permission.notification.statuson iOS ends up in+[NotificationPermissionStrategy permissionStatus], which callsgetNotificationSettingsWithCompletionHandler:and then blocks the main thread on a semaphore withDISPATCH_TIME_FOREVER. If the settings callback needs the main queue, it never returns.On the iOS 27 simulator this is 100% reproducible for us: our app reads the notification status at startup and stays on the launch screen forever after a cold start (9.6.2). Main thread of the hung process:
requestPermission:reads the status the same way first, andCriticalAlertsPermissionStrategyhas the identical pattern. No other strategy uses a semaphore.Changes
Went with the approach suggested in the comment on #1420, same as #1100 did for
checkServiceStatus:PermissionStrategygets an optionalcheckPermissionStatus:completionHandler:. Other strategies are untouched.PermissionManageruses it when the strategy implements it and callsresulton the main queue.getNotificationSettingsWithCompletionHandler:without the semaphore, andrequestPermission:uses it too.The settings →
PermissionStatusmapping didn't change, I just moved it into+permissionStatusFromSettings:so both paths share it.Tests
The example app had no native test target, so I added
RunnerTestswith one XCTest that calls the plugin on the main thread and expects the result to come back asynchronously. It fails (or hangs) on 9.6.2 and passes with the fix on the iOS 27.0 simulator, both with SwiftPM and CocoaPods:Also checked in our app on the iOS 27 simulator: it gets past the launch screen now.
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.