Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Apple HealthKit getSleepSample returns 0

$
0
0

I am trying to pull the sleep data from the Health app using react native. However every time I run it the getSleepSample return 0. My code for this is below.

let options = {
  startDate: (new Date(2019,10,25)).toISOString(),
  endDate: (new Date(2019,11,10)).toISOString(),
  limit: 10,
  permissions: {
      read: ["Height", "Weight", "StepCount", "DateOfBirth", "BodyMassIndex", "ActiveEnergyBurned", "SleepAnalysis"],
      write: ["Height", "Weight", "StepCount", "BodyMassIndex", "Biotin", "Caffeine", "Calcium", "Carbohydrates", "Chloride", "Cholesterol", "Copper", "EnergyConsumed", "FatMonounsaturated", "FatPolyunsaturated", "FatSaturated", "FatTotal", "Fiber", "Folate", "Iodine", "Iron", "Magnesium", "Manganese", "Molybdenum", "Niacin", "PantothenicAcid", "Phosphorus", "Potassium", "Protein", "Riboflavin", "Selenium", "Sodium", "Sugar", "Thiamin", "VitaminA", "VitaminB12", "VitaminB6", "VitaminC", "VitaminD", "VitaminE", "VitaminK", "Zinc", "Water"]
  }};

  componentDidMount(){
    AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => {
      if (err) {
          console.log("error initializing Healthkit: ", err);
          return;
      }
    AppleHealthKit.getSleepSamples(options, (err: Object, results: Array<Object>) => {
      if (err) {
        console.log(err);
        return;
      }
      console.log(results.length)
      this.setState({sleep:results.length})
    }); 
  });
  }

I am not sure if the problem is with the dates or the way I am calling the method. I have tried it with the getStepCount method and that works fine.


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>