lucaspbordignon / rn-apple-healthkit

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

0.7.3 is not reading workouts, (while 0.6.5 is) #127

Open IceDev-xyz opened 4 years ago

IceDev-xyz commented 4 years ago

Same code, iOS 13. The latest version of this package lost the availability of reading workouts.

Untitled-1

thkus commented 4 years ago

It seems, that this is caused by a recent change made in RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m

Workout is mapped to MindfulSession. If i use this permission instead, i see workouts again.

terrillo commented 4 years ago

@IceDev-xyz @thkus I'll take a look at this issue today

gamertense commented 4 years ago

It seems, that this is caused by a recent change made in RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m

Workout is mapped to MindfulSession. If i use this permission instead, i see workouts again.

You're right. When I opened RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m file, I saw this:

if ([@"MindfulSession" isEqualToString: key] && systemVersion >= 10.0) {
        return [HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierMindfulSession];
    } else if ([@"MindfulSession" isEqualToString: key]){
        return [HKObjectType workoutType];
    }

and then I realised something a bit weird here: if ([@"MindfulSession" isEqualToString: key] is shown on both if statements.

So I changed the code from:

else if ([@"MindfulSession" isEqualToString: key]){
     return [HKObjectType workoutType];
}

to:

else if ([@"Workout" isEqualToString: key]){
     return [HKObjectType workoutType];
}

and now I can get workout data.

Thank you for pointing out. You just saved my day!

paulmars commented 4 years ago

forked and used it here for now

https://github.com/paulmars/rn-apple-healthkit
    const options = {
      permissions: {
        read: ["Height", "Weight", "SleepAnalysis", "MindfulSession", "Workout", "Steps"],
        write: ["Height", "Weight"],
      },
    };

    AppleHealthKit.initHealthKit(options, (err, results) => {
      if (err) {
        console.log("error initializing Healthkit: ", err);
        return;
      }

      // Height Example
      AppleHealthKit.getDateOfBirth(null, (err, results) => {
        console.log(results)
      });
    });
rameshvishnoi90904 commented 4 years ago

@terrillo any update on this? can i create MR for this?

gamertense commented 4 years ago

@terrillo any update on this? can i create MR for this?

For now, you can change content in package.json to:

"rn-apple-healthkit": "https://github.com/paulmars/rn-apple-healthkit",

and run rm -rf node_modules && yarn install again. You can change it back later when the author has merged change.

paulmars commented 4 years ago

I never brought this idea into production. Don't assume it works as desired. Comments or alterations welcome.