Skip to content

Commit

Permalink
Merge branch 'master' into revert-113-fix/infinite_update_useStatisti…
Browse files Browse the repository at this point in the history
…csForQuantity
  • Loading branch information
robertherber committed Nov 13, 2024
2 parents 5ef9e9c + 5a58db6 commit 2bf9475
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Test
# Controls when the action will run.
on:
push:
branches: [ "**" ]
pull_request:
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
Expand Down
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,26 @@ Some imperative examples:
console.log(quantity) // 17.5
console.log(unit) // %

/* Listen to data */
await HealthKit.requestAuthorization([HKQuantityTypeIdentifier.heartRate]); // request read permission for heart rate

/* Make sure to request permissions before subscribing to changes */
const unsubscribe = HealthKit.subscribeToChanges(HKQuantityTypeIdentifier.heartRate, () => {
// refetch whichever queries you need
});
/* Subscribe to data (Make sure to request permissions before subscribing to changes) */
const [hasRequestedAuthorization, setHasRequestedAuthorization] = useState(false);

useEffect(() => {
HealthKit.requestAuthorization([HKQuantityTypeIdentifier.heartRate]).then(() => {
setHasRequestedAuthorization(true);
});
}, []);

useEffect(() => {
if (hasRequestedAuthorization) {
const unsubscribe = HealthKit.subscribeToChanges(HKQuantityTypeIdentifier.heartRate, () => {
// refetch data as needed
});
}

return () => unsubscribe();
}, [hasRequestedAuthorization]);

/* write data */
await HealthKit.requestAuthorization([], [HKQuantityTypeIdentifier.insulinDelivery]); // request write permission for insulin delivery
Expand Down
2 changes: 1 addition & 1 deletion src/native-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ export enum HKUnits {
Percent = '%',
Count = 'count',
InternationalUnit = 'IU',
AppleEffortScore = "appleEffortScore"
AppleEffortScore = 'appleEffortScore'
}

export type MeterUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =
Expand Down

0 comments on commit 2bf9475

Please sign in to comment.