Giter VIP home page Giter VIP logo

rn-apple-healthkit's Introduction

React Native Apple Healthkit

A React Native bridge module for interacting with Apple Healthkit data. Checkout the full documentation

Installation

Install the [rn-apple-healthkit] package from npm:

  • Run npm install rn-apple-healthkit --save
  • Run react-native link rn-apple-healthkit
  • Run cd ./ios && pod install
  • Update ./ios/<Project Name>/info.plist in your React Native project
<key>NSHealthShareUsageDescription</key>
<string>Read and understand health data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>
  • Enable Healthkit in your application's Capabilities
  • Build and run

Get Started

Initialize Healthkit. This will show the Healthkit permissions prompt for any read/write permissions set in the required options object.

Due to Apple's privacy model if an app user has previously denied a specific permission then they can not be prompted again for that same permission. The app user would have to go into the Apple Health app and grant the permission to your react-native app under sources tab.

For any data that is read from Healthkit the status/error is the same for both. This privacy restriction results in having no knowledge of whether the permission was denied (make sure it's added to the permissions options object), or the data for the specific request was nil (ex. no steps recorded today).

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 if not present.

If new read/write permissions are added to the options object then the app user will see the Healthkit permissions prompt with the new permissions to allow.

initHealthKit requires an options object with Healthkit permission settings

import AppleHealthKit from 'rn-apple-healthkit';

let options = {
    permissions: {
        read: ["Height", "Weight"],
        write: ["Height", "Weight"]
    }
};

AppleHealthKit.initHealthKit(options, (err, results) => {
    if (err) {
        console.log("error initializing Healthkit: ", err);
        return;
    }

    // Height Example
    AppleHealthKit.getDateOfBirth(null, (err, results) => {
      console.log(results)
    });

});

Height Example Response

{
	value: '1986-09-01T00:00:00.000-0400',
	age: 29
}

Wiki

Supported Apple Permissions

The available Healthkit permissions to use with initHealthKit

Permission Healthkit Identifier Type Read Write
ActiveEnergyBurned HKQuantityTypeIdentifierActiveEnergyBurned
BasalEnergyBurned HKQuantityTypeIdentifierBasalEnergyBurned
BiologicalSex HKCharacteristicTypeIdentifierBiologicalSex
BloodGlucose HKQuantityTypeIdentifierBloodGlucose
BloodPressureDiastolic HKQuantityTypeIdentifierBloodPressureDiastolic
BloodPressureSystolic HKQuantityTypeIdentifierBloodPressureSystolic
BodyMassIndex HKQuantityTypeIdentifierBodyMassIndex
BodyTemperature HKQuantityTypeIdentifierBodyTemperature
DateOfBirth HKCharacteristicTypeIdentifierDateOfBirth
DistanceCycling HKQuantityTypeIdentifierDistanceCycling
DistanceWalkingRunning HKQuantityTypeIdentifierDistanceWalkingRunning
FlightsClimbed HKQuantityTypeIdentifierFlightsClimbed
HeartRate HKQuantityTypeIdentifierHeartRate
Height HKQuantityTypeIdentifierHeight
LeanBodyMass HKQuantityTypeIdentifierLeanBodyMass
MindfulSession HKCategoryTypeIdentifierMindfulSession
RespiratoryRate HKQuantityTypeIdentifierRespiratoryRate
SleepAnalysis HKCategoryTypeIdentifierSleepAnalysis
StepCount HKQuantityTypeIdentifierStepCount
Steps HKQuantityTypeIdentifierSteps
Weight HKQuantityTypeIdentifierBodyMass
BodyFatPercentage HKQuantityTypeIdentifierBodyFatPercentage

These permissions are exported as constants of the rn-apple-healthkit module.

import AppleHealthKit from 'rn-apple-healthkit';

// get the available permissions from AppleHealthKit.Constants object
const PERMS = AppleHealthKit.Constants.Permissions;

// setup healthkit read/write permissions using PERMS
const healthKitOptions = {
    permissions: {
        read:  [
            PERMS.StepCount,
            PERMS.Height,
        ],
        write: [
            PERMS.StepCount
        ],
    }
};

Units

  • bpm
  • calorie
  • celsius
  • count
  • day
  • fahrenheit
  • foot
  • gram
  • hour
  • inch
  • joule
  • meter
  • mgPerdL
  • mile
  • minute
  • mmhg
  • mmolPerL
  • percent
  • pound
  • second

References

This package is an original fork of react-native-apple-Healthkit

rn-apple-healthkit's People

Contributors

gregwilson avatar ejohnf avatar terrillo avatar furyou81 avatar friendlyuis avatar skleest avatar adbl avatar allenan avatar adamivancza avatar opsb avatar svbutko avatar shaharyarmaroof avatar alexovits avatar yogiyadavmca avatar dmatora avatar iradkot avatar ohneeszett avatar thkus avatar mcrowder65 avatar mateuszprasal avatar martinrp avatar jacquerie avatar toml0006 avatar iradkot-herolo avatar hellocore avatar benjaminpaap avatar

Watchers

James Cloos avatar

Forkers

healthbitco

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.