Package Exports
- @kilohealth/rn-fitness-tracker
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kilohealth/rn-fitness-tracker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
rn-fitness-tracker
React Native library for step tracking based on Google Fit (Android) and CoreMotion (iOS) native API's.
Installation
$ npm install @kilohealth/rn-fitness-tracker --save
or
$ yarn add @kilohealth/rn-fitness-tracker
iOS
react-native 0.60.x
- Add following line to Podfile:
pod 'RNFitnessTracker', :podspec => '../node_modules/@kilohealth/rn-fitness-tracker/ios/RNFitnessTracker.podspec' - Add following lines to info.plist file
<dict>tag:
<key>NSMotionUsageDescription</key>
<string>Reason string goes here</string>or
open ios project in XCode. Navigated to info.plist file. Add new property list key - NSMotionUsageDescription. This will add new line in the containing Privacy - Motion Usage Description.
manual linking for projects with older react-native version
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜@kilohealth/rn-fitness-trackerand addRNFitnessTracker.xcodeproj - In XCode, in the project navigator, select your project. Add
libRNFitnessTracker.ato your project'sBuild Phases➜Link Binary With Libraries
Android
- To get an OAuth 2.0 Client ID for your project, follow steps in Google Fit documentation.
- Then in Google API console find Fitness API and enable it. Download your
google-services.jsonfile from firebase console and place it insideandroid/appdirectory within your project. - Add following dependencies to
android/app/build.gradlefile:
implementation 'com.google.android.gms:play-services-fitness:16.0.1'
implementation 'com.google.android.gms:play-services-auth:16.0.1'react-native 0.60.x
React Native autolinking will handle the rest.
manual linking for projects with older react-native version
Open up
android/app/src/main/java/[...]/MainActivity.javaAddimport com.fitnesstracker.RNFitnessTrackerPackage;to the imports at the top of the file. Addnew RNFitnessTrackerPackage()to the list returned by thegetPackages()method.Append the following lines to
android/settings.gradle:
include ':@kilohealth-rn-fitness-tracker'
project(':@kilohealth-rn-fitness-tracker').projectDir = new File(rootProject.projectDir, '../node_modules/@kilohealth/rn-fitness-tracker/android')3.Insert the following lines inside the dependencies block in android/app/build.gradle:
implementation project(path: ':@kilohealth-rn-fitness-tracker')Usage
import RNFitnessTracker from 'rn-fitness-tracker';
//Check if this app has a permission to track steps
//this function can only be used on iOS.
//Status - String (
// 'authorized'/
// 'notDetermined'/
// 'denied'/
// 'restricted'/
// 'unauthorized'/
// 'undefined')
RNFitnessTracker.isAuthorizedToUseCoreMotion( status => {});
//This step is required in order to use any of the methods bellow
//status - boolean
RNFitnessTracker.authorize( status => {});
//get steps today
RNFitnessTracker.getStepsToday( steps => {});
//get 7 days steps
//steps - integer
RNFitnessTracker.getWeekData( steps => {});
//to get 7 days steps
//data - object
// {
// '2019-07-08 12:00:00' : 100,
// '2019-07-07 12:00:00' : 267,
// }
RNFitnessTracker.getDailyWeekData( data => {});