kingstinct / react-native-healthkit

HealthKit bindings for React Native with TypeScript
https://kingstinct.com/react-native-healthkit/
MIT License
219 stars 45 forks source link

Couldn't save active energy #101

Open SergiOnGit opened 1 month ago

SergiOnGit commented 1 month ago

I save workout sample like this:

let workoutOptions = {
                end: endDate,
                totals: {
                    energyBurned: calories,
                    activeEnergyBurned: calories,
                },
}

await HealthKit.saveWorkoutSample(66, [], startDate, workoutOptions);

It saves workout but not an active energy.

if calories are 100, apple health app shows related sample 100kcal total active energy, but when i click it, active energy page is empty.

IMG_0098 IMG_0099

robertherber commented 1 month ago

I haven't saved workouts with active energy myself. Are you sure it's not just a matter of how it's presented by the Apple Health app?

One thing I've noted before is when manually (as a user - in the Apple Health app) adding active energy it doesn't seem to affect the Apple Watch rings (which I guess makes sense from a cheating standpoint :). Might be a related pattern.

gitleef commented 1 month ago

@SergiOnGit Do you mind sharing how you request authorization for saving a workout sample, and how you configured the plugin in app.config.js? I have been trying everything to get the workout write authorization to work, but nothing works for me. Thank you.

SergiOnGit commented 1 month ago

@SergiOnGit Do you mind sharing how you request authorization for saving a workout sample, and how you configured the plugin in app.config.js? I have been trying everything to get the workout write authorization to work, but nothing works for me. Thank you.

const permissions = {
    read: [],
    write: [
        HKQuantityTypeIdentifier.height,
        HKQuantityTypeIdentifier.bodyMass,
        HKQuantityTypeIdentifier.activeEnergyBurned,
        HKWorkoutTypeIdentifier,
    ],
};

await HealthKit.requestAuthorization(permissions.read, permissions.write);

This is how I request authorization. I don't have anything in app.config.js, I simply add important keys to info.plist like this:

`NSHealthShareUsageDescription

Read and understand health data.
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with applekit.</string>`
SergiOnGit commented 1 month ago

I haven't saved workouts with active energy myself. Are you sure it's not just a matter of how it's presented by the Apple Health app?

One thing I've noted before is when manually (as a user - in the Apple Health app) adding active energy it doesn't seem to affect the Apple Watch rings (which I guess makes sense from a cheating standpoint :). Might be a related pattern.

I am not sure if it should be as it is, users started complaining about it, so I think there is a problem.