Skip to content

Allow querying Bluetooth service status on iOS (Apple) - #1100

Merged
mvanbeusekom merged 3 commits into
Baseflow:mainfrom
JeroenWeener:773/apple
Jul 13, 2023
Merged

mvanbeusekom merged 3 commits into
Baseflow:mainfrom
JeroenWeener:773/apple

Conversation

@JeroenWeener

Copy link
Copy Markdown
Contributor

This PR updates the Apple implementation, fixing an issue where the Bluetooth service status was never resolved properly. To this end it

  • Makes checkServiceStatus async
  • Keeps track of PermissionStrategy in PermissionManager (hold the reference to guarantee that the callback fires)

Additionally, it updates the displayed permission in the example app, as these were out of sync with the newest permissions.

This PR is part of feature #773.

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.

@mvanbeusekom mvanbeusekom 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.

The update to use a completion block looks really useful. The current implementation however does contain a bug (see comment).

Additionally I feel the BluetoothPermissionStrategy.checkServiceStatus might not cover all cases where the service is enabled.

Makes `checkServiceStatus` async.
Keeps track of `PermissionStrategy` in `PermissionManager`.
Updates example app's displayed permissions.

@mvanbeusekom mvanbeusekom 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.

LGTM

@mvanbeusekom
mvanbeusekom merged commit 74ffdfb into Baseflow:main Jul 13, 2023
mvanbeusekom added a commit that referenced this pull request Oct 23, 2026
…in thread (#1573)

`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 #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 #1420

Co-authored-by: Maurits van Beusekom <[email protected]>
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