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
$ yarn add @kilohealth/rn-fitness-tracker
iOS
React-Native > 0.61
- Add following lines to info.plist file
<dict>tag:
<key>NSMotionUsageDescription</key>
<string>Reason string goes here</string>or
Navigate to info.plist file in XCode ➜ Add new property list key - NSMotionUsageDescription.
This will add new line in the containing Privacy - Motion Usage Description.
React-Native < 0.60 - Manual linking for projects with older react-native version
- Add following line to Podfile:
pod 'RNFitnessTracker', :podspec => '../node_modules/@kilohealth/rn-fitness-tracker/ios/RNFitnessTracker.podspec'. - 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
React-Native > 0.61
- Enable Google Fitness Api:
Setting up Android Fit API permissions
Make sure your Google account has access to app firebase project.
Create an OAuth screen for your project.
Select
User Type: Externaland fill out the form. Add../auth/fitness.activity.readto Scopes for Google APIs.Fill out next popup forms with a brief explanation why you're using the activity tracker (no need to write much).
Go to Google console
Select your app's project,
Continue, andGo to Credentials.Where will you be calling the API from? Select
Android.What data will you be accessing? Select
User dataand click next.The Signing-certificate fingerprint generation command must be pointed to your app release / staging keystore file.
Save and submit everything. If you haven't got your google services config inside your app - download your
google-services.jsonfile from firebase console and place it insideandroid/appdirectory within your project.
- React Native autolinking should handle the rest.
React-Native < 0.60
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')
implementation 'com.google.android.gms:play-services-fitness:16.0.1'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
Usage
import RNFitnessTracker from 'rn-fitness-tracker';
// This step is required in order to use any of the methods bellow
// Returns an object:
// authorized: boolean;
// shouldOpenAppSettings: boolean;
// trackingNotSupported?: boolean;
RNFitnessTracker.setupTracking(status => {});
// Get steps today
RNFitnessTracker.getStepsToday(steps => {});