Permissions and Workout data? https://ionicframework.com/docs/native/health-kit

We are having issues with the permissions on this (Health Kit - Ionic Documentation) to get both step data AND workout data at the same time. Also the plugin for getting workout data takes no parameters and returns every workout ever? Is there no alternative/a better way to do this?

The functions we are using…

Workouts - findWorkouts()

The call we want to use to get Workout permission as well is called requestAuthorization(). It feels like we cant find the correct identifier to get workouts here as well as step data.

Our current requestAuthorization call is as below:

requestOptions: HealthKitOptions = {
readTypes: ['HKQuantityTypeIdentifierStepCount'],
writeTypes: ['HKQuantityTypeIdentifierStepCount']
};
this.healthKit.requestAuthorization(this.requestOptions).then(success => {
console.log('auth success', success);
this.checkAppleHealthPermissions();
}, error => {
console.log('auth error', error);
});

The below call also always hits the error, never the success if they have allowed or denied access:

this.healthKit.findWorkouts().then(success1 => {
// for some reason never hits here
console.log('workouts1', success1);
}, success2 => {
console.log('workouts2', success2);
});

Are you testing this in a simulator or on a real device? Also, what do the logs in xcode tell you?

this is on a real device

There are no crash logs in xcode - what other log info would you want to see?

Well not crash logs, but xcode typically has some output depending on the success or failure of a native call.

Since this is using cordova, Im not 100% sure if this matters or not, but have you checked to make sure that the healthkit capabilities are enabled?

The HealthKit capability has been added when setting up our app certificate from the developer portal. However was not added as a capability in xCode. I have since added this and the behaviour was the exact same.

I have pulled off the debug logs (see attached) and can see, when we request access to HealthKit for steps the log contains information around this. However when we initiate the workouts data call/permissions there is nothing.

Seems so bizarre so tested this a couple more times and always the same both functionary and log wise.

the steps code we are using is…
healthKit.requestAuthorization
followed by healthKit.querySampleTypeAggregated

the workouts code is…
healthKit.findWorkouts
(which seems to do the permissions and data in one go)

2021-05-04 14:29:59.087262+0100 [APP NAME][346:9514] Health store returned authorization status: undetermined for type HKQuantityTypeIdentifierStepCount

2021-05-04 14:30:01.993926+0100 [APP NAME][346:9514] Requesting read permissions for HKQuantityTypeIdentifierStepCount
2021-05-04 14:30:01.994050+0100 [APP NAME][346:9514] Requesting write permission for HKQuantityTypeIdentifierStepCount

2021-05-04 14:30:07.151044+0100 [APP NAME][346:9514] Health store returned authorization status: authorized for type HKQuantityTypeIdentifierStepCount

Hi Mike,

Just wondered if you had any thoughts on this?

Thanks
Tom