1.3.2 • Published 3 years ago
healthsnap.mobile.healthapis v1.3.2
healthsnap.mobile.healthapis
A React Native bridge module for interacting with Apple Healthkit and Google Fit
Installation
- Run
yarn add @healthsnap/healthsnap.js.apihealthsnap.mobile.healthapis
- 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>
- Enable Healthkit in your application's
Capabilities
- Build and run
Usage
import HealthApi,
{
Permissions,
Units,
} from '@healthsnap/healthsnap.mobile.healthapis';
const config = {
permissions: {
read: [
Permissions.activeEnergy,
Permissions.age,
Permissions.bodyFatPercentage,
Permissions.bloodPressureDiastolic,
Permissions.bloodPressureSystolic,
Permissions.gender,
Permissions.height,
Permissions.restingHeartRate,
Permissions.waistCircumference,
Permissions.weight,
Permissions.vo2Max,
Permissions.oxygenSaturation,
],
}
};
// the options object is used to setup a query to retrieve relevant samples.
const options = {
startDate: (new Date(2016,4,27)).toISOString(), // optional; default null
endDate: (new Date()).toISOString(), // optional; default now
};
const HealthApiHandler = (err, value) => err ? console.log(err) : console.log(value);
HealthApi.init(config, (err) => {
if (err) {
console.log("error initializing Healthkit: ", err);
return;
}
HealthApi.getDateOfBirth(null, (err, age) => HealthApiHandler(err, { age }));
HealthApi.getBiologicalSex(null, (err, gender) => HealthApiHandler(err, { gender }));
HealthApi.getLatestWeight(null, (err, latestWeight) => HealthApiHandler(err, { latestWeight }));
HealthApi.getLatestHeight(null, (err, latestHeight) => HealthApiHandler(err, { latestHeight }));
HealthApi.getLatestBodyFatPercentage(null, (err, latestBodyFat) => HealthApiHandler(err, { latestBodyFat }));
HealthApi.getLatestWaistCircumference(null, (err, latestWaistCircumference) => HealthApiHandler(err, { latestWaistCircumference }));
HealthApi.getLatestBloodPressure(null, (err, latestBloodPressure) => HealthApiHandler(err, { latestBloodPressure }));
HealthApi.getLatestRestingHeartRate(null, (err, latestRestingHeartRate) => HealthApiHandler(err, { latestRestingHeartRate }));
HealthApi.getAverageActiveEnergyBurned(options, (err, energy) => HealthApiHandler(err, { energy }));
HealthApi.getLatestVO2Max(null, (err, vo2Max) => HealthApiHandler(err, { vo2Max }));
});
1.3.2
3 years ago
1.3.1
4 years ago
1.3.0
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.0
4 years ago
1.0.0
4 years ago
0.6.0
4 years ago
0.5.1
4 years ago
0.4.1
4 years ago
0.4.0
4 years ago
0.3.2
4 years ago
0.3.3
4 years ago
0.3.1
4 years ago
0.2.0
4 years ago
0.1.0
4 years ago
0.0.1
4 years ago