lucaspbordignon / rn-apple-healthkit

A React Native package for interacting with Apple HealthKit
https://www.npmjs.com/package/react-native-health
MIT License
520 stars 298 forks source link

Cannot read body fat percentage.. #50

Open shrinandhini2801 opened 5 years ago

shrinandhini2801 commented 5 years ago

Unable to read body fat percentage even though there is a method in doc ==> AppleHealthKit.getLatestBodyFatPercentage.

Am getting below error

{"message":"error getting latest body fat percentageError Domain=com.apple.healthkit Code=5 \"Authorization not determined\" UserInfo={NSLocalizedDescription=Authorization not determined}"}

raginisahu commented 5 years ago

did you find any solution?

Luke-Gurgel commented 4 years ago

When you run AppleHealthKit.initHealthKit(options, (err, results), you need to pass an options object, which should contain a read property that contains all the stuff you want read access to. You just need to add body fat in that list, like so:

[https://github.com/terrillo/rn-apple-healthkit/blob/master/docs/initHealthKit().md](https://github.com/terrillo/rn-apple-healthkit/blob/master/docs/initHealthKit().md)

const healthKitOptions = {
  permissions: {
    read: ['BodyFatPercentage']
  }
};

Considering that permission to read BodyFatPercentage may not have been granted, you might also want to consider running AppleHealthKit.authorizationStatusForType() beforehand.

[https://github.com/terrillo/rn-apple-healthkit/blob/master/docs/authorizationStatusForType().md](https://github.com/terrillo/rn-apple-healthkit/blob/master/docs/authorizationStatusForType().md)