npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@track-info/rn-health-kit

v1.0.13

Published

Fork of rn-apple-healthkit

Downloads

7

Readme

React Native Healthkit

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

Installation

  • npm install @track-info/rn-health-kit --save

react-native >= 0.60.x

  • cd ios && pod install && cd ..

react-native <= 0.59.10

  • react-native link @track-info/rn-health-kit

Manual Installation

If your project uses react-native >= 0.60.x and you want to install the package manually, add a react-native.config.js file to your project's root directory (if one doesn't exist already), and configure @track-info/rn-health-kit like so:

module.exports = {
  dependencies: {
    '@track-info/rn-health-kit': {
      platform: { ios: null }
    }
  }
}
  1. In Xcode, in the project navigator, right click LibrariesAdd Files to [your project's name]node_modules@track-info/rn-health-kit and add RCTAppleHealthkit.xcodeproj
  2. Still in Xcode, in the project navigator, select your project ➜ select your project's target ➜ scroll down to Link Binary With Libraries at the bottom ➜ Add libRCTAppleHealthkit.a

Setup

  1. Update 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>
  1. Enable Healthkit in your application's Capabilities tab, like so:

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

let options = {
    permissions: {
        read: ["Height", "Weight", "StepCount", "DateOfBirth", "BodyMassIndex", "ActiveEnergyBurned"],
        write: ["Height", "Weight", "StepCount", "BodyMassIndex", "Biotin", "Caffeine", "Calcium", "Carbohydrates", "Chloride", "Cholesterol", "Copper", "EnergyConsumed", "FatMonounsaturated", "FatPolyunsaturated", "FatSaturated", "FatTotal", "Fiber", "Folate", "Iodine", "Iron", "Magnesium", "Manganese", "Molybdenum", "Niacin", "PantothenicAcid", "Phosphorus", "Potassium", "Protein", "Riboflavin", "Selenium", "Sodium", "Sugar", "Thiamin", "VitaminA", "VitaminB12", "VitaminB6", "VitaminC", "VitaminD", "VitaminE", "VitaminK", "Zinc", "Water"]
    }
};
import HealthKit from '@track-info/rn-health-kit';

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

    // Height Example
    HealthKit.getDateOfBirth(null, (err: Object, results: Object) => {
    if (this._handleHealthkitError(err, 'getDateOfBirth')) {
      return;
    }
      console.log(results)
    });

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

Changelog

0.6.5v

  • Enable fetching basal energy #23
  • remove checkPermission functions in order to use from PR #69
  • Added correct link to permissions. #73
  • Add unified way to get workouts + convert Activity Types to name + isTracked flag #25

0.6.4v

  • Basal energy (#23)
  • Fixed issues with saving weight in the past
  • Commited the docs to increase pull request support
  • Add daily samples for:
    • Flights Climbed
    • WalkingRunning Distance
    • Cycling Distance

0.6.3v

  • Food and Water (#19)

0.6.1v

  • HKQuantityTypeIdentifierActiveEnergyBurned

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 @track-info/rn-health-kit module.

import HealthKit from '@track-info/rn-health-kit';

// get the available permissions from HealthKit.Constants object
const PERMS = HealthKit.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