You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,6 +117,41 @@ this.healthData.query(
117
117
.catch(error=>this.resultToShow=error);
118
118
```
119
119
120
+
121
+
### `startMonitoring` (iOS only, for now)
122
+
If you want to be notified when health data was changed, you can monitor specific types. This even works when your app is in the background, with `enableBackgroundUpdates: true`. Note that iOS will wake up your app so you can act upon this notification (in the `onUpdate` function by fi. querying recent changes to this data type), but in return you are responsible for telling iOS you're done. So make sure you invoke the `completionHandler` as shown below.
123
+
124
+
Not all data types support `backgroundUpdateFrequency: "immediate"`, so your app may not always be invoked immediately when data is added/deleted in HealthKit.
125
+
126
+
> Background notifications probably don't work on the iOS simulator, so please test those on a real device.
127
+
128
+
```typescript
129
+
this.healthData.startMonitoring(
130
+
{
131
+
dataType: dataType,
132
+
enableBackgroundUpdates: true,
133
+
backgroundUpdateFrequency: "immediate",
134
+
onUpdate: (completionHandler: () =>void) => {
135
+
console.log("Our app was notified that health data changed, so querying...");
0 commit comments