1.7.1 • Published 4 years ago

react-native-fitness-sdk v1.7.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

react-native-fitness-sdk · npm version npm

Powered By POPiN

Installation

With npm

  • Run npm install react-native-fitness-sdk --save
  • Run npm install react-native-background-fetch --save

React-native <= 0.60

  • Run react-native link react-native-fitness-sdk

React-native >= 0.60

  • Run cd ./ios && pod install

Additional steps

  • Update ./ios/<Project Name>/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>

Get Started

Initialize Healthkit => initFitnessSdk() This will show the Health-kit permissions prompt for any read/write permission included in the options argument. By default no argument is required and the SDK will prompt the following list of permissions: "Height", "Weight".

If you need to use more functionalities or read more data, you must add an {options} argument and include a list of permissions as shown below:

let options = {   readData:  "Height", "Weight", "ActiveEnergyBurned", "BodyFatPercentage", "BodyMassIndex", "BasalEnergyBurned", "DistanceCycling", "DistanceWalkingRunning", "FlightsClimbed", "HeartRate", "StepCount"   }

initFitnessSdk(options)

Example (reading height)

import { 
  initFitnessSdk,
  getHeight
} from 'react-native-fitness-sdk';

// *** SDK initialization method + getHeight *** //
// By default the SDK will ask for the following permissions:
// read: ["Height", "Weight"]

initFitnessSdk()
.then(()=> {
  let date = "2020-01-01" // Date must be this format
  getHeight(date).then(res => alert(res)).catch(err => alert(err))
});

Methods

Global Methods

Method nameArgumentsNotes
initHealthKit{options}This will show the Healthkit permissions prompt for any read/write permission included in the options object. The "options" argument is not required and by default the SDK will ask for the following permissions: "Height", "Weight".
checkFitnessSdkInitThis will check if the SDK was initialized
fitnessSdkBackgroundTaskThis will trigger the background task
openHealthKitThis will open the health-kit app
collectNewDataThis will show all the available data collected by the SDK at the current time
collectAndPostNewDataThis will send all new available data at the current time to the API

Read Data

Method nameArgumentsNotes
getBodyMassIndex
getHeight
getWeight
getBodyFatPercentage
getActiveEnergyBurnedstartDate, endDateAccepts 2 arguments, startDate (required) and endDate (optional; default now).
getBasalEnergyBurnedstartDate, endDateAccepts 2 arguments, startDate (required) and endDate (optional; default now).
getDistanceCyclingdate, unitAccepts a date as argument (optional; default now) and a unit (defaults to meter).
getDistanceWalkingRunningdate, unitAccepts a date as argument (optional; default now) and a unit (defaults to meter).
getFlightsClimbeddateAccepts a date as argument (optional; default now).
getHeartRatestartDate, endDateAccepts 2 arguments, startDate (required) and endDate (optional; default now).
getStepsdateAccepts a date as argument.

API Fitness Data Actions

Method nameArgumentsNotes
fetchFitnessProfileuserProfile, startDate, endDateFirst argument required
fetchFitnessActivitiesuserProfile, startDate, endDateFirst argument required
fetchFitnessActivityuserProfile, activityId, startDate, endDateFirst two arguments required
fetchFitnessMeasurementsuserProfile, startDate, endDateFirst argument required
fetchFitnessMeasurementuserProfile, measurementId, startDate, endDateFirst two arguments required

:heavy_exclamation_mark: startDate or endDate arguments must be in this format YYYY-MM-DD

Debugging

Read Data Actions

  • Any "readData" action (they are all promises) will return a value, an array of values or an error. The error will come through in case data or permission is missing. For this reason there is currently no way to check if a specific permission is granted or not and the sdk will always throw the same error => Missing data or permission.

  • From the apple developer website: "To help prevent possible leaks of sensitive health information, your app cannot determine whether or not a user has granted permission to read data. If you are not given permission, it simply appears as if there is no data of the requested type in the HealthKit store. If your app is given share permission but not read permission, you see only the data that your app has written to the store. Data from other sources remains hidden."

  • Due to Apple's privacy model if an app user has previously denied a specific permission then he 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 the react-native app under sources tab.

Bakground event

  • Simulate background fetch events in XCode using Debug->Simulate Background Fetch (Note: You are FORCING a background fetch to be run. This will run the successFn even if the #stop method has been called. In practice, iOS won't fire fetch events after you've called #stop)

  • iOS can take some hours or even days to start a consistently scheduling background-fetch events since iOS schedules fetch events based upon the user's patterns of activity. If Simulate Background Fetch works, your can be sure that everything is working fine. You just need to wait.

License

The MIT License

COPYRIGHT 2020, POPIN, INC. https://www.popin.io/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.7.1

4 years ago

1.7.0

4 years ago

1.6.8

4 years ago

1.6.7

4 years ago

1.6.6

4 years ago

1.6.4

4 years ago

1.6.5

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.9

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.6

4 years ago

1.5.5

4 years ago

1.5.4

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.9

4 years ago

1.4.8

4 years ago

1.4.7

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.8

4 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.0.0

4 years ago