Skip to content

feat(ios): add getRequestStatusForAuthorization - #499

Open
touyou wants to merge 2 commits into
carp-dk:mainfrom
touyou:feat/ios-get-request-status-for-authorization
Open

feat(ios): add getRequestStatusForAuthorization#499
touyou wants to merge 2 commits into
carp-dk:mainfrom
touyou:feat/ios-get-request-status-for-authorization

Conversation

@touyou

@touyou touyou commented Jun 9, 2026

Copy link
Copy Markdown

Motivation

On iOS, hasPermissions always returns null for read types because
HealthKit deliberately does not expose read-authorization status to apps
(see #939 and many related reports). As a result, apps cannot tell a
first-time authorization request from one the user has already answered,
which makes it impossible to branch permission UX correctly (e.g. show a
request flow vs. guide the user to the Health app to change an existing
decision).

HealthKit exposes exactly this signal via
HKHealthStore.getRequestStatusForAuthorization(toShare:read:),
but the plugin doesn't surface it. This PR adds a thin wrapper.

What's new

  • Dart: Health.getRequestStatusForAuthorization(List<HealthDataType> types, {List<HealthDataAccess>? permissions})
    returning a new HealthAuthorizationRequestStatus enum
    (shouldRequest / unnecessary / unknown). Returns null on Android.
  • iOS: new getRequestStatusForAuthorization method-channel handler in
    HealthDataOperations, mirroring requestAuthorization's read/write set
    building, then calling getRequestStatusForAuthorization(toShare:read:) and
    mapping HKAuthorizationRequestStatus.
  • Tests: argument validation, the non-iOS null path, channel forwarding
    and enum mapping.
  • CHANGELOG entry.

Important caveat (documented in the API)

This reports whether the authorization sheet would still be shown, not
whether read access was granted — HealthKit never exposes read-grant
status. The dartdoc states this explicitly so callers don't misuse it as a
"is read allowed?" check.

Backward compatibility

Purely additive. No existing API changes. Android behaviour is a no-op
(null), guarded on the Dart side so no platform channel call is made there.

touyou added 2 commits June 9, 2026 15:29
`hasPermissions` always returns null for read types on iOS because HealthKit
does not expose read-authorization status. This makes it impossible to tell a
first-time request from an already-answered one.

Add `getRequestStatusForAuthorization`, a thin wrapper over HealthKit's
`HKHealthStore.getRequestStatusForAuthorization(toShare:read:)`, which reports
whether the authorization sheet would still be shown (`shouldRequest`) or not
(`unnecessary`). It does not reveal whether read access was granted — HealthKit
never exposes that — but it lets apps branch their permission UX.

- Dart: `Health.getRequestStatusForAuthorization(types, {permissions})` returning
  a new `HealthAuthorizationRequestStatus` enum. Returns null on Android.
- iOS: new method-channel handler mirroring `requestAuthorization`'s read/write
  set building.
- Tests for argument validation, the non-iOS null path, channel forwarding and
  enum mapping.
@codoffer

Copy link
Copy Markdown

Any udpate?

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