rn-apple-healthkit icon indicating copy to clipboard operation
rn-apple-healthkit copied to clipboard

0.7.3 is not reading workouts, (while 0.6.5 is)

Open IceDev-xyz opened this issue 5 years ago • 7 comments
trafficstars

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

Untitled-1

IceDev-xyz avatar Nov 26 '19 19:11 IceDev-xyz

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.

thkus avatar Dec 13 '19 16:12 thkus

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

terrillo avatar Dec 13 '19 16:12 terrillo

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!

gamertense avatar Jan 31 '20 08:01 gamertense

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)
      });
    });

paulmars avatar Feb 14 '20 00:02 paulmars

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

rameshvishnoi90904 avatar Apr 25 '20 13:04 rameshvishnoi90904

@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.

gamertense avatar Apr 26 '20 09:04 gamertense

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

paulmars avatar Apr 26 '20 19:04 paulmars