All Projects → OvalMoney → React Native Fitness

OvalMoney / React Native Fitness

Licence: mit
A React Native module to interact with Apple Healthkit and Google Fit.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to React Native Fitness

BoxVR-Playlist-Manager
A Windows based playlist manager for the VR fitness game BoxVR
Stars: ✭ 17 (-92.8%)
Mutual labels:  fitness
Phormatics
Using A.I. and computer vision to build a virtual personal fitness trainer. (Most Startup-Viable Hack - HackNYU2018)
Stars: ✭ 79 (-66.53%)
Mutual labels:  fitness
Tapiriik
tapiriik keeps your fitness in sync
Stars: ✭ 1,604 (+579.66%)
Mutual labels:  fitness
Personal Dashboard
📊 Programmatically collecting and reporting various stats about myself daily
Stars: ✭ 333 (+41.1%)
Mutual labels:  fitness
Fitly
Self hosted web analytics for endurance athletes
Stars: ✭ 65 (-72.46%)
Mutual labels:  fitness
Wger
Self hosted FLOSS fitness/workout, nutrition and weight tracker written with Django
Stars: ✭ 1,372 (+481.36%)
Mutual labels:  fitness
fitness app clone
This is the fitness app clone.
Stars: ✭ 16 (-93.22%)
Mutual labels:  fitness
Vrworkout
High-intensity virtual reality workout game
Stars: ✭ 166 (-29.66%)
Mutual labels:  fitness
Fitness
Flutter 仿微博客户端!A Weibo client application developed with Flutter, which supports both Android and iOS.
Stars: ✭ 75 (-68.22%)
Mutual labels:  fitness
Bodyweight Fitness Ios
Bodyweight Fitness (iOS)
Stars: ✭ 115 (-51.27%)
Mutual labels:  fitness
Vmpy
VMPY - Performance Velo Metrics Toolbox
Stars: ✭ 8 (-96.61%)
Mutual labels:  fitness
Health Blockchain
A blockchain for fitness data demo
Stars: ✭ 31 (-86.86%)
Mutual labels:  fitness
Fitness android
Android健身app,在普通健身app的基础上加入了社交功能(类似KEEP、FEEL、轻+、减约、薄荷等) 毕设项目
Stars: ✭ 107 (-54.66%)
Mutual labels:  fitness
Bodyweight Fitness Android
Bodyweight Fitness (Android)
Stars: ✭ 297 (+25.85%)
Mutual labels:  fitness
Gymnasticon
Make obsolete and/or proprietary exercise bikes work with popular cycling training apps like Zwift, TrainerRoad, Rouvy and more.
Stars: ✭ 155 (-34.32%)
Mutual labels:  fitness
traindown
Public site
Stars: ✭ 35 (-85.17%)
Mutual labels:  fitness
Stayfit
📱 🏃 🍎 Fitness application that’s used to keep track of your physical fitness data, daily calorie count, invite friends to work out together and ultimately get healthy.
Stars: ✭ 90 (-61.86%)
Mutual labels:  fitness
Choochoo
Training Diary
Stars: ✭ 186 (-21.19%)
Mutual labels:  fitness
Hitrava
Convert your Huawei Health sport activities and import them in Strava.
Stars: ✭ 156 (-33.9%)
Mutual labels:  fitness
Fastnfitness
FastNFitness Android app: Body, Cardio and Fitness tracking.
Stars: ✭ 113 (-52.12%)
Mutual labels:  fitness

react-native-fitness

react-native-fitness is a 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 or distance 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 @ovalmoney/react-native-fitness --save

or

yarn add @ovalmoney/react-native-fitness

Mostly automatic installation

react-native link @ovalmoney/react-native-fitness

Manual installation

iOS

Pods

  1. Add the line below to your Podfile.
    pod 'react-native-fitness', :path => '../node_modules/@ovalmoney/react-native-fitness'`
    
  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-fitness.a.
  4. Add following to your Info.plist in order to ask permissions.
    <key>NSHealthShareUsageDescription</key>
    <string>Read and understand health data.</string>
    

Manually

  1. In XCode's project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modules@ovalmoneyreact-native-fitness and select RNFitness.xcodeproj
  3. In XCode select your project, go to Build PhasesLink Binary With Libraries and add libRNFitness.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. Get an OAuth 2.0 Client ID as explained at https://developers.google.com/fit/android/get-api-key
  2. Open up MainApplication.java
    • Add import com.ovalmoney.fitness.RNFitnessPackage; to the imports at the top of the file
    • Add new RNFitnessPackage() to the list returned by the getPackages() method
  3. Append the following lines to android/settings.gradle:
    include ':@ovalmoney_react-native-fitness'
    project(':@ovalmoney_react-native-fitness').projectDir = new File(rootProject.projectDir, 	'../node_modules/@ovalmoney/react-native-fitness/android')
    
  4. Insert the following lines inside the dependencies block in android/app/build.gradle:
    compile project(':@ovalmoney_react-native-fitness')
    
  5. (Optional) In order to better handle the right versions, add in your android/build.gradle:
      // Other build versions
      fitnessPlayServices: "<Your version>" // default: 17.0.0
      authPlayServices: "<Your version>" // default: 17.0.0
    }
    

Usage

import Fitness from '@ovalmoney/react-native-fitness';

const permissions = [
  { kind: Fitness.PermissionKinds.Steps, access: Fitness.PermissionAccesses.Write },
];

Fitness.isAuthorized(permissions)
  .then((authorized) => {
    // Do something
  })
  .catch((error) => {
    // Do something
  });

API

  • Fitness.isAuthorized([{ kind: int, access: int }]) Check if permissions are granted or not. It works on Android and iOS >= 12.0, while it returns an error when iOS < 12. It requires an Array of Object with a mandatory key kind and an optional key access. Possible values for the keys can be found in PermissionKinds and PermissionAccesses under Attributes section. On iOS at least one permissions with Read access must be provided, otherwise an errorEmptyPermissions will be thrown.

  • Fitness.requestPermissions([{ kind: int, access: int }]) Ask permission and return if user granted or not(Android), while, due to Apple's privacy model, always true is returned in iOS. It requires an Array of Object with a mandatory key kind and an optional key access. Possible values for the keys can be found in PermissionKinds and PermissionAccesses under Attributes section. On iOS at least one permissions with Read access must be provided, otherwise an errorEmptyPermissions will be thrown.

  • Fitness.logout() Available only on android. It performs a logout from google account. It returns true for a successful logout, false if user cancel action.

  • Fitness.disconnect() Available only on android. It performs a disconnect action from Google Fit. It returns true for a successful logout, false if user cancel action.

  • Fitness.getSteps({ startDate: string, endDate: string, interval: string }) 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. Set interval to decide how detailed the returned data is, set it to hour or minute otherwise it defaults to days.

  • Fitness.getDistances({ startDate: string, endDate: string, interval: string }) 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. Set interval to decide how detailed the returned data is, set it to hour or minute otherwise it defaults to days.

  • Fitness.getCalories({ startDate: string, endDate: string, interval: string }) 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. Set interval to decide how detailed the returned data is, set it to hour or minute otherwise it defaults to days.

  • Fitness.getHeartRate({ startDate: string, endDate: string, interval: string }) 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. Set interval to decide how detailed the returned data is, set it to hour or minute otherwise it defaults to days.

  • Fitness.getSleepAnalysis({ startDate: string, endDate: string }) Fetch sleep analysis data 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.

  • Fitness.subscribeToActivity() Available only on android. Subscribe to all Google Fit activities. It returns a promise with true for a successful subscription and false otherwise. Call this function to get all google fit activites and eliminate the need to have Google Fit installed on the device.

  • Fitness.subscribeToSteps() Available only on android. Subscribe only to steps from the Google Fit store. It returns a promise with true for a successful subscription and false otherwise. Call this function to get steps and eliminate the need to have Google Fit installed on the device.

Attributes

Platform

Return the used provider.

PermissionKinds

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

  • Steps: to required the access for Steps
  • Distances: to required the access for Distances
  • Calories: to required the access for Calories
  • HeartRate: to required the access for Heart rate
  • Activity: to required the access for Activity (only Android)
  • SleepAnalysis: to required the access for Sleep Analysis

PermissionAccesses

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

Errors

Return the list of meaningful errors that can be possible thrown.

iOS

Possible values are:

  • 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
Android

Possible values are:

  • methodNotAvailable: thrown if getSleepAnalysis is called on Android less than N
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].