@@ -27,16 +27,16 @@ following:
27
27
If you followed the [ Background Processing] ( https://github.com/agencyenterprise/react-native-health#background-processing )
28
28
step in the README, you can skip this one.
29
29
30
- To setup that in your project, in XCode open your ` ios/AppDelegate.m ` file and add the
31
- following statements:
30
+ To setup that in your project, in XCode open your ` ios/AppDelegate.m ` file and uncomment the
31
+ lines with a comment ` Uncomment this line to use background observers ` :
32
+
32
33
33
34
``` objective-c
34
35
#import " AppDelegate.h"
35
36
36
37
...
37
38
38
- /* Add the library import at the top of AppDelegate.m */
39
- #import " RCTAppleHealthKit.h"
39
+ // #import "RCTAppleHealthKit.h" // <-- Uncomment this line to use background observers
40
40
41
41
...
42
42
@@ -50,8 +50,7 @@ following statements:
50
50
51
51
...
52
52
53
- /* Add Background initializer for HealthKit * /
54
- [[ RCTAppleHealthKit new] initializeBackgroundObservers: bridge ] ;
53
+ // [[ RCTAppleHealthKit new] initializeBackgroundObservers: bridge ] ; // <-- Uncomment this line to use background observers
55
54
56
55
...
57
56
@@ -88,17 +87,17 @@ up observers for workouts, the events would have the following names:
88
87
### Example
89
88
90
89
```typescript
91
- import { NativeAppEventEmitter } from 'react-native'
92
-
93
- const callback = (): void => {
94
- /* Execute any data query */
95
- }
96
-
97
- /* Register native listener that will be triggered when successfuly enabled */
98
- NativeAppEventEmitter.addListener('healthKit:HeartRate:setup:success', callback)
99
-
100
- /* Register native listener that will be triggered on each update */
101
- NativeAppEventEmitter.addListener('healthKit:HeartRate:new', callback)
90
+ import React, { useEffect } from 'react';
91
+ import { NativeEventEmitter, NativeModules } from 'react-native';
92
+
93
+ useEffect(() => {
94
+ new NativeEventEmitter(NativeModules.AppleHealthKit).addListener(
95
+ 'healthKit:HeartRate:new',
96
+ async () => {
97
+ console.log('--> observer triggered');
98
+ },
99
+ );
100
+ });
102
101
```
103
102
104
103
When a new sample appears, in order to get the information you need to call
0 commit comments