ReviewOS

craft-native/craft

HealthKit has no dietary types, so an app asking for them silently reads nothing

#351
Closed glennmichael123 opened this 9 days ago ·
9 days ago

CraftHealth.requestAuthorization maps type names to HKObjectTypes with a switch that ends:

default:
    break

An unrecognised name is dropped without a word. With readOnly: true the share set is cleared as well, so an app whose types are all unrecognised calls healthStore.requestAuthorization(toShare: [], read: []) — which succeeds without showing a sheet, and every later query then fails with errorAuthorizationNotDetermined.

The types it knows: steps, heartRate, activeEnergy, distance, workouts, restingHeartRate, heartRateVariability, bodyMass, sleep.

Missing: the dietary ones. stacksjs/hq.training has just shipped a food log that asks for dietaryEnergy, dietaryProtein, dietaryCarbohydrates and dietaryFat. HealthKit has all four — .dietaryEnergyConsumed, .dietaryProtein, .dietaryCarbohydrates, .dietaryFatTotal — but Craft has no cases for them, so the feature reads nothing and says nothing about why.

Two things worth doing, and the second matters more than the first:

  1. Add the dietary quantity types, for read and for write — a food log wants to write what the person logged, not only read what other apps wrote.
  2. Stop dropping unknown types in silence. default: break turns a typo or a version skew into a feature that quietly does nothing. Returning an error naming the unrecognised type, or at minimum an NSLog, would have made this a five-minute problem instead of a feature that appears to work.

The same silence applies to any app ahead of Craft's type list, which is the normal case while both are moving.

9 days ago

Resolved on main by 8e78df9 (feat(ios): read the days food from Apple Health) and the follow-up validation. CraftHealth maps dietaryEnergy, dietaryProtein, dietaryCarbohydrates, and dietaryFat for read/write authorization and rejects unknown types instead of dropping them. Coverage is in packages/ios/src/index.test.ts; the focused suite passes 217 tests with 0 failures.

Sign in to comment on this issue.