Skip to content

Commit 8c7db4e

Browse files
authored
Merge pull request #277 from agencyenterprise/enhancement/update-example-app
Example app update
2 parents 3b741e3 + 348ee42 commit 8c7db4e

File tree

10 files changed

+2943
-2558
lines changed

10 files changed

+2943
-2558
lines changed

docs/background.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ step in the README, you can skip this one.
3030
To setup that in your project, in XCode open your `ios/AppDelegate.m` file and add the
3131
following statements:
3232

33+
3334
```objective-c
3435
#import "AppDelegate.h"
3536

@@ -88,17 +89,17 @@ up observers for workouts, the events would have the following names:
8889
### Example
8990
9091
```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)
92+
import React, { useEffect } from 'react';
93+
import { NativeEventEmitter, NativeModules } from 'react-native';
94+
95+
useEffect(() => {
96+
new NativeEventEmitter(NativeModules.AppleHealthKit).addListener(
97+
'healthKit:HeartRate:new',
98+
async () => {
99+
console.log('--> observer triggered');
100+
},
101+
);
102+
});
102103
```
103104

104105
When a new sample appears, in order to get the information you need to call

example/App.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState} from 'react';
1+
import React, {useState, useEffect} from 'react';
22
import {
33
SafeAreaView,
44
StyleSheet,
@@ -14,6 +14,8 @@ import AppleHealthKit, {
1414
HealthKitPermissions,
1515
} from 'react-native-health';
1616

17+
import {NativeEventEmitter, NativeModules} from 'react-native';
18+
1719
/* Permission options */
1820
const permissions = {
1921
permissions: {
@@ -46,6 +48,15 @@ AppleHealthKit.initHealthKit(permissions, (error: string) => {
4648
export default function App() {
4749
const [authStatus, setAuthStatus] = useState<any>({});
4850

51+
useEffect(() => {
52+
new NativeEventEmitter(NativeModules.AppleHealthKit).addListener(
53+
'healthKit:HeartRate:new',
54+
async () => {
55+
console.log('--> observer triggered');
56+
},
57+
);
58+
});
59+
4960
const handlePressGetAuthStatus = () => {
5061
AppleHealthKit.getAuthStatus(permissions, (err, result) => {
5162
if (err) {

example/ios/Podfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require_relative '../node_modules/react-native/scripts/react_native_pods'
22
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
33

4-
platform :ios, '10.0'
4+
platform :ios, '13.0'
55

66
target 'example' do
77
config = use_native_modules!
@@ -20,6 +20,9 @@ target 'example' do
2020
use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })
2121
post_install do |installer|
2222
flipper_post_install(installer)
23+
installer.pods_project.build_configurations.each do |config|
24+
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
25+
end
2326
end
2427
end
2528

0 commit comments

Comments
 (0)