0

I downloaded from Apple (https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/build_a_workout_app_for_apple_watch) the Workout app and tried to add requestAuthorization for the following types and then to read it.

func requestAuthorization() {
    // The quantity type to write to the health store.
    let typesToShare: Set = [
        HKQuantityType.workoutType(),
        HKQuantityType.quantityType(forIdentifier: .heartRate)!,
        HKQuantityType.quantityType(forIdentifier: .oxygenSaturation)!,
        HKQuantityType.quantityType(forIdentifier: .vo2Max)!,
    ]

    // The quantity types to read from the health store.
    let typesToRead: Set = [
        HKQuantityType.quantityType(forIdentifier: .heartRate)!,
        HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)!,
        HKQuantityType.quantityType(forIdentifier: .distanceWalkingRunning)!,
        HKQuantityType.quantityType(forIdentifier: .distanceCycling)!,
        HKQuantityType.quantityType(forIdentifier: .oxygenSaturation)!,
        HKQuantityType.quantityType(forIdentifier: .vo2Max)!,
        HKObjectType.activitySummaryType()
    ]

    // Request authorization for those quantity types.
    healthStore.requestAuthorization(toShare: typesToShare, read: typesToRead) { (success, error) in
        // Handle error.
    }
}

But unfortunately everything except vo2Max and oxygenSaturation is working.

My goal is to get the oxygenSaturation in my own app. Is this even possible?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Osman
  • 1,496
  • 18
  • 22
  • Yes, you can read those data types. Are you getting no results? Is there data on the device? i.e. if you go to Preferences -> Health -> Health Data -> Activity/Respiratory, do you see vo2max/SpO2 values? Note that this data may or may not be written while your workout is in progress like the other types you have listed. But you should be able to read historical data. – psolanki Nov 03 '21 at 16:26
  • I am getting result which I record over the iPhone app (https://support.apple.com/en-us/HT211027) but my goal is to record/write over my own app like the heart rate. – Osman Nov 03 '21 at 18:00
  • @psolanki can you share code or give some more tipps ? I can't figured out .. – Osman Nov 04 '21 at 10:15
  • Are you saying you're getting data on iPhone but not on watchOS? These types are not generated during a workout so if you're expecting them during a workout session that may not work. What does your query code for these data types look like? How is it different on phone from watch? – psolanki Nov 04 '21 at 20:30
  • @psolanki no sorry my mistake i didn't explain well. I am just using the watchOS and wanted to get the current oxygen data not the historical data which I have recorded with the apple (Blood Oxygen) App. – Osman Nov 04 '21 at 21:26
  • The watch saves blood oxygen data when the app is used and automatically at certain intervals during the day. You can't manually trigger a blood oxygen reading or expect that one would be taken during a workout. Same with VO2max. – psolanki Nov 08 '21 at 03:41

0 Answers0