Skip to content

Commit

Permalink
Merge pull request #277 from agencyenterprise/enhancement/update-exam…
Browse files Browse the repository at this point in the history
…ple-app

Example app update
  • Loading branch information
GGGava authored Jan 16, 2023
2 parents 3b741e3 + 348ee42 commit 8c7db4e
Show file tree
Hide file tree
Showing 10 changed files with 2,943 additions and 2,558 deletions.
23 changes: 12 additions & 11 deletions docs/background.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ step in the README, you can skip this one.
To setup that in your project, in XCode open your `ios/AppDelegate.m` file and add the
following statements:


```objective-c
#import "AppDelegate.h"

Expand Down Expand Up @@ -88,17 +89,17 @@ up observers for workouts, the events would have the following names:
### Example
```typescript
import { NativeAppEventEmitter } from 'react-native'
const callback = (): void => {
/* Execute any data query */
}
/* Register native listener that will be triggered when successfuly enabled */
NativeAppEventEmitter.addListener('healthKit:HeartRate:setup:success', callback)
/* Register native listener that will be triggered on each update */
NativeAppEventEmitter.addListener('healthKit:HeartRate:new', callback)
import React, { useEffect } from 'react';
import { NativeEventEmitter, NativeModules } from 'react-native';
useEffect(() => {
new NativeEventEmitter(NativeModules.AppleHealthKit).addListener(
'healthKit:HeartRate:new',
async () => {
console.log('--> observer triggered');
},
);
});
```

When a new sample appears, in order to get the information you need to call
Expand Down
13 changes: 12 additions & 1 deletion example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState} from 'react';
import React, {useState, useEffect} from 'react';
import {
SafeAreaView,
StyleSheet,
Expand All @@ -14,6 +14,8 @@ import AppleHealthKit, {
HealthKitPermissions,
} from 'react-native-health';

import {NativeEventEmitter, NativeModules} from 'react-native';

/* Permission options */
const permissions = {
permissions: {
Expand Down Expand Up @@ -46,6 +48,15 @@ AppleHealthKit.initHealthKit(permissions, (error: string) => {
export default function App() {
const [authStatus, setAuthStatus] = useState<any>({});

useEffect(() => {
new NativeEventEmitter(NativeModules.AppleHealthKit).addListener(
'healthKit:HeartRate:new',
async () => {
console.log('--> observer triggered');
},
);
});

const handlePressGetAuthStatus = () => {
AppleHealthKit.getAuthStatus(permissions, (err, result) => {
if (err) {
Expand Down
5 changes: 4 additions & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'
platform :ios, '13.0'

target 'example' do
config = use_native_modules!
Expand All @@ -20,6 +20,9 @@ target 'example' do
use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })
post_install do |installer|
flipper_post_install(installer)
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
end

Expand Down
Loading

0 comments on commit 8c7db4e

Please sign in to comment.