• Stars
    star
    874
  • Rank 52,219 (Top 2 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A React Native package to interact with Apple HealthKit

React Native Health

A React Native package to interact with Apple HealthKit for iOS. Maintained with ❤️ by AE Studio.

This package allows access to health & fitness data exposed by Apple Healthkit. You can see the methods available here.

If you are looking for a more robust solution providing normalized data, insights and recommendations based on user's biometric data, data from multiple sources (Fitbit, Oura), or a hosted solution, please check out the Point SDK developed by our frens.

Discord

React Native Health official Discord

Getting Started

🚨 Expo: This package is not available in the Expo Go app. Learn how you can use it with custom dev clients.

Automatic Installation

  1. Install the react-native-health package from npm
yarn add react-native-health
  1. If you are using CocoaPods you can run the following from the ios/ folder of your app
pod install

Or, if you need to manually link it, run

react-native link react-native-health
  1. Update the ios/<Project Name>/info.plist file in your project
<key>NSHealthShareUsageDescription</key>
<string>Read and understand health data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>
<!-- Below is only required if requesting clinical health data -->
<key>NSHealthClinicalHealthRecordsShareUsageDescription</key>
<string>Read and understand clinical health data.</string>

To add Healthkit support to your application's Capabilities

  • Open the ios/ folder of your project in Xcode
  • Select the project name in the left sidebar
  • In the main view select '+ Capability' and double click 'HealthKit'

To enable access to clinical data types, check the Clinical Health Records box.

Usage

In order to start collecting or saving data to HealthKit, you need to request the user's permissions for the given data types. It can be done in the following way

import AppleHealthKit, {
  HealthValue,
  HealthKitPermissions,
} from 'react-native-health'

/* Permission options */
const permissions = {
  permissions: {
    read: [AppleHealthKit.Constants.Permissions.HeartRate],
    write: [AppleHealthKit.Constants.Permissions.Steps],
  },
} as HealthKitPermissions

AppleHealthKit.initHealthKit(permissions, (error: string) => {
  /* Called after we receive a response from the system */

  if (error) {
    console.log('[ERROR] Cannot grant permissions!')
  }

  /* Can now read or write to HealthKit */

  const options = {
    startDate: new Date(2020, 1, 1).toISOString(),
  }

  AppleHealthKit.getHeartRateSamples(
    options,
    (callbackError: string, results: HealthValue[]) => {
      /* Samples are now collected from HealthKit */
    },
  )
})

Background Processing

For background capabilities, Apple allows developers to setup long running observer queries for the health types needed.

To set that up in your app, in XCode open your ios/AppDelegate.m file and add the following statements:

#import "AppDelegate.h"

...

/* Add the library import at the top of AppDelegate.m */
#import "RCTAppleHealthKit.h"

...

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self
                                            launchOptions:launchOptions];

  ...

  /* Add Background initializer for HealthKit  */
  [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge];

  ...

  return YES;
}

After that you can start listening for data updates using the React Native client. For more information, see background observers.

Documentation

There is a gitbook version for the documentation here.

All the documentation is under the docs folder. They are split into the following categories:

Constants

Base Methods

Background Methods

Activity Methods

Body Methods

Characteristic Methods

Clinical Records Methods

Dietary Methods

Fitness Methods

Hearing Methods

Lab Tests Methods

Nutrition

Mindfulness Methods

Sleep Methods

Vitals Methods

Workout Methods

Additional Information

Permissions

Due to Apple's privacy model, if a user has previously denied a specific permission they will not be prompted again for that permission. The user will need to go into the Apple Health app and grant the permission to your app.

For any data written to Healthkit, an authorization error can be caught. If an authorization error occurs, you can prompt the user to set the specific permission or add the permission to the options object when initializing the library.

If extra read or write permissions are added to the options object, the app will request the user's permission when the library is initialized again.

Manual Installation

  1. Run yarn add react-native-health
  2. In XCode, in the project navigator, right-click LibrariesAdd Files to [your project's name]
  3. Go to node_modulesreact-native-health and add RCTAppleHealthkit.xcodeproj
  4. In XCode, in the project navigator, select your project. Add libRCTAppleHealthkit.a to your project's Build PhasesLink Binary With Libraries
  5. Click RCTAppleHealthkit.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). In the Search Paths section, look for Header Search Paths and make sure it contains both $(SRCROOT)/../../react-native/React and $(SRCROOT)/../../../React - mark both as recursive.
  6. Enable Healthkit in your application's Capabilities
  7. Compile and run

Contributing

We appreciate any requests and contributions to react-native-health. The issues tracker is used to keep a list of features and bugs to be worked on. Please see our contributing documentation for some tips on getting started.

References

Android Alternative

If your app needs an Android + Health Connect integration, your princess is in another castle. You can use the package React Native Health Connect maintained by one of the community's dev.

In case of questions or if you just want to congratz the author, you can reach out to him on our Discord Server.

Acknowledgement

This package is a fork of rn-apple-healthkit

This package also inherits additional features from Nutrisense fork

Plz I Still Need Halp

This package is maintained with ❤️ by AE Studio. We will do our best to respond to requests and support for this package so please get in touch! If you require more extensive help or have other design, data science or development needs - we are a full service product development agency and can build pretty much anything so hit us up!

More Repositories

1

PromptInject

PromptInject is a framework that assembles prompts in a modular fashion to provide a quantitative analysis of the robustness of LLMs to adversarial prompt attacks. 🏆 Best Paper Awards @ NeurIPS ML Safety Workshop 2022
Python
290
star
2

neurotechdevkit

Neurotech Development Kit (NDK)
Python
115
star
3

neural-data-simulator

Electrophysiology data simulator for developing brain-computer interfaces
Python
70
star
4

clickwheel-js

JavaScript
64
star
5

px-cli

🪄 Package manager eXecutor for JavaScript projects
JavaScript
49
star
6

Term-Typer-Words

JavaScript
31
star
7

aeboilerplate

AEboilerplate is an opinionated boilerplate that creates a full-stack React/Node Typescript project, with independent client and API structures in the same repository, ready to run and deploy.
TypeScript
26
star
8

tableexplorer

TypeScript
25
star
9

ascii-only

A Shopify script to block non-ascii characters at the checkout page text inputs
JavaScript
17
star
10

imagined-handwriting

An alternative implementation for an imagined handwriting decoder
Python
12
star
11

hiring-developer

This is our exercise for developers. We evaluate necessary programming skills and patterns. See the job description on our website.
12
star
12

cadence-webpack-plugin

Webpack plugin that helps importing .cdc files
JavaScript
10
star
13

nullstack-tailwind

CSS
8
star
14

AnalyzingNeuralTimeSeries-Python

Python Implementation of Code for ANTS book (Cohen, 2012, MIT Press)
Jupyter Notebook
8
star
15

zkgraph-bnb-hack

A zkml framework based on the Libra procotol for proving onnx and general numpy computations built with pure python.
Python
8
star
16

barbell

Barbell is an tiny open source newsfeed directly on the macOS Menu Bar. Seamlessly track multiple sources like Reddit, Twitter, and Hacker News.
6
star
17

docstring-auditor

Use AI to review your code documentation
Python
5
star
18

ndx-nirs

An NWB extension for storing Near-Infrared Spectroscopy (NIRS) data
Python
5
star
19

woodpecker

🐦 A Woodpecker Javascript API
JavaScript
5
star
20

go-libp2p-pubsub-benchmark-tools

libp2p/go-libp2p-pubsub benchmark tools
Go
5
star
21

zkRamp

🏆 Winner Project at AlephZero Hackathon: zkRamp is a protocol that aims to quickly and efficiently provide onramp/offramp solutions using zero-knowledge proofs.
TypeScript
4
star
22

tdc-talk-nft

TypeScript
3
star
23

alpha-ai-avatar-sdk-react

Alpha AI Avatar SDK (React)
TypeScript
2
star
24

Hacker-News-Menu-Feed

Swift
2
star
25

notehacker

Your hacker way to do notes
JavaScript
2
star
26

masky

A client-side mask detector app
TypeScript
2
star
27

50b-zk-worker

Python
2
star
28

quack

TypeScript
2
star
29

montyhallpoker

Montyhall Casino - A fully function web3 poker engine written on move for the Aptos blockchain
TypeScript
2
star
30

zerokdb

A zk SQL DB with semantic search features
TypeScript
2
star
31

zk-credit-analysis

🏆 Winner Project at ScalingX ZK Hackathon: ZK Credit Score
TypeScript
1
star
32

0k

A ZKML framework for pythonistas
Python
1
star
33

ai-branch-name-generator

TypeScript
1
star
34

pem-utils

Simple script to create private keys and ipfs ids
Go
1
star
35

metamask-safelogin-example

JavaScript
1
star
36

security-ninja-code-scanner

1
star
37

hack-2023-ae-faucet

TypeScript
1
star
38

finger-tapping-fnirs-to-nwb

Convert an fNIRS dataset for a finger tapping task to NWB format
Python
1
star
39

block-watcher

JavaScript
1
star
40

50b-zk-web

TypeScript
1
star
41

point-ios

Swift
1
star
42

harvest-autotimer

Chrome extension to auto start/stop harvest time entry when starting/finishing a story on pivotal tracker.
JavaScript
1
star
43

mkdocs-offline-links-plugin

mkdocs plugin to enable offline browsing via file explorer
Python
1
star
44

ketchup

hackathon project: vscode extension with Pomodoro management time
TypeScript
1
star
45

serpro-web3-hackathon

🏆 Winner Project at Tesouro Nacional Hackathon: ZScore WEB3
JavaScript
1
star
46

soundchain-contracts

TypeScript
1
star
47

hack-2023-story-visualizer

JavaScript
1
star
48

50b-zk-hub

TypeScript
1
star