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

@memorres/react-native-fitnesskit

v1.1.0

Published

A React Native package that gives you access to Apple Health kit and Google Fit data.

Downloads

8

Readme

react-native-fitnesskit

react-native-fitnesskit is a fitness library that works on both iOS and Android with it you can interact with Apple Healthkit and Google Fit. Currently the lib provides a set of API that you can use to read steps count, distance count, HeartRate count, Energy count for a given period of time. Note: We're open to receive PRs that contains new features or improvements, so feel free to contribute to this repo.

Getting started

npm install @memorres/react-native-fitnesskit --save or yarn add @memorres/react-native-fitnesskit

Mostly automatic installation

react-native link @memorres/react-native-fitnesskit

Manual installation

iOS

Pods

  1. Add the line below to your Podfile.
    pod 'react-native-fitnesskit', :path => '../node_modules/@memorres/react-native-fitnesskit'`
  2. Run pod install in your iOS project directory.
  3. In XCode, select your project, go to Build PhasesLink Binary With Libraries and add libreact-native-fitnesskits.a.
  4. Add following to your Info.plist in order to ask permissions.
    <key>NSHealthShareUsageDescription</key>
    <string>Read and understand health data.</string>
    <key>NSHealthUpdateUsageDescription</key>
    <string>Share workout data with other apps.</string>

Manually

  1. In XCode's project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesmemorresrereact-native-fitnesskit and select RNFitnesskit.xcodeproj`
  3. In XCode select your project, go to Build PhasesLink Binary With Libraries and add libRNFitnesskit.a.
  4. Run your project (Cmd+R) In order to make it run, it is necessary to turn on Health Kit in the Capabilities.

Android

  1. Use below link to enable google fit api on google console. https://console.developers.google.com/flows/enableapi?apiid=fitness
  2. Open up MainApplication.java
    • Add import com.memorres.fitnesskit.RNFitnesskitPackage; to the imports at the top of the file
    • Add new RNFitnesskitPackage() to the list returned by the getPackages() method
  3. Append the following lines to android/settings.gradle:
    include ':@memorres_react-native-fitnesskit'
    project(':@memorres_react-native-fitnesskit').projectDir = new File(rootProject.projectDir, 	'../node_modules/@memorres/react-native-fitnesskit/android')
  4. Insert the following lines inside the dependencies block in android/app/build.gradle:
    compile project(':@memorres_react-native-fitnesskit')

Get Started

  1. Initialize Fitnesskit. This will show the Fitnesskit permissions prompt for any read permissions.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
  2. 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.

Usage

import Fitnesskit,{Permission} from 'react-native-fitnesskit';
let options = {
  permissions: {
      read: [Permission.StepCount,Permission.Distance],
      write:[Permission.StepCount,Permission.Distance]
  }
};
Fitness.isAuthorized(permissions)
  .then((authorized) => {
    // Do something
  })
  .catch((error) => {
    // Do something
  });

API

  • Fitness.isAuthorized(permissions) Check if permissions are granted or not. It works on Android >= google play services 7.0 or higher and iOS >=12.0 ,while it returns an error if condition not satisfied.
  • Fitness.requestPermissions(permissions)
Fitnesskit.requestPermissions(options)
           .then((success) => {
                     })
           .catch((err) => {
                     });
  • Fitness.getStepCount() Fetch steps on a given period of time. It requires an Object with startDate and endDate attributes as string. If startDate is not provided an error will be thrown.
let optionsSteps = {
   startDate: "2020-4-17",
   endDate:   "2020-4-21",
   };
 Fitnesskit.getStepCount(optionsSteps).then(res => {
}).catch(err => {
  });
  • Fitness.getDistance() Fetch distance in meters on a given period of time. It requires an Object with startDate and endDate attributes as string. If startDate is not provided an error will be thrown.
let options = {
  startDate: "2020-4-17",
  endDate:   "2020-4-21",
  type:     Permission.Distance,
};

Here type is only for ios becuase ios provide also distance for DistanceSwimming and DistanceCycling and default type parameter for ios is DistanceWalkingRunning

  • Fitness.getEnergy() Fetch calories burnt in kilocalories on a given period of time.. It requires an Object with startDate and endDate attributes as string. If startDate is not provided an error will be thrown.
let options = {
  startDate: "2020-4-17",
  endDate:   "2020-4-21",
  type:     Permission.Energy,
};

Here type is only for ios becuase ios provide also energy for BasalEnergyBurned and DietaryEnergy and default and default type parameter for ios is ActiveEnergyBurned

  • Fitness.getHeartRate() Fetch heart rate bpm on a given period of time. It requires an Object with startDate and endDate attributes as string. If startDate is not provided an error will be thrown.

Attributes

Platform

Return the used provider.

PermissionKind

Return the information of what kind of Permission can be asked. At the moment the list of possible kinds is:

  • StepCount: to required the access for Step
  • Distance: to required the access for DistanceWalkingRunning for ios and Distance for android
  • DistanceSwimming: to required the access for DistanceSwimming only for ios
  • DistanceCycling: to required the access for DistanceCycling only for ios
  • Energy: to required the access for Calorie for android and ActiveEnergyBurned for ios
  • BasalEnergyBurned: to required the access for BasalEnergyBurned only for ios
  • DietaryEnergy: to required the access for DietaryEnergy only for ios
  • HeartRate: to required the access for Heart rate

PermissionAccess

Return the information of what kind of Access can be asked. The list of possible kinds is:

  • Read: to required the access to Read
  • Write: to required the access to Write

Error

Return the list of meaningful errors that can be possible thrown. On Android below error occur. dateNotCorrect: thrown if received date is not correct Possible error for iOS only

  • hkNotAvailable: thrown if HealthKit is not available
  • methodNotAvailable: thrown if isAuthorized is called on iOS < 12.0
  • dateNotCorrect: thrown if received date is not correct
  • errorEmptyPermissions: thrown if no read permissions are provided
  • errorNoEvents: thrown if an error occurs while try to retrieve data