Closed novakben closed 9 years ago
Hi, what device are you testing this on?
Btw, you should check whether or not isAvailable
is true before calling the requestAuthorization
function.
Hey Eddy!
iPhone 5 runninng the latest iOS. I'm using HealthKit with other apps so there's no device specific problem.
I've revised the code to check if true, All the console logs get fired, the permission dialog still does'nt
here's the revised code:
// after checking window.plugins and window.plugins.healthkit are available, do:
if (window.plugins) {
window.plugins.healthkit.available(
function(isAvailable) {
if (isAvailable === true) {
console.log('HEALTHKIT AVAILABLE, REQUESTING PERMISSIONS')
window.plugins.healthkit.requestAuthorization(
{
'readTypes' : ['HKCharacteristicTypeIdentifierDateOfBirth', 'HKQuantityTypeIdentifierActiveEnergyBurned', 'HKQuantityTypeIdentifierHeight'],
'writeTypes' : ['HKQuantityTypeIdentifierActiveEnergyBurned', 'HKQuantityTypeIdentifierHeight', 'HKQuantityTypeIdentifierDistanceCycling']
},
console.log('SUCCESS'),
console.log('ERROR')
);
}
}
);
}
Hmm, can you try removing your app and reinstalling it? Perhaps you're requesting a permission you previously denied. HK doesn't show the permission popup in that case.
Tried it, still nothing :/
Damn.. guessing here.. does your app have the HealthKit entitlement?
Aha! not yet, I havn't created anything in apple developer yet, do I need to do it even if I am not uploading my app to the appstore yet?
To my knowledge: yes. I hope this fixes the problem.
I'll set it up now and let you know!
Ok I created the HealthKit provisions, but that didn't work so I started playing with xCode and I found the culprit! You have to set healthkit in xcode capabiliteis as well.
See attached image
Now I can get the permission and when trying to write the sample workout I get the permission again to allow to add workouts, after I give permission I don't see that the workout registered on the health kit screen.
That's the code:
window.plugins.healthkit.saveWorkout({
'activityType': 'HKWorkoutActivityTypeCycling',
'quantityType': 'HKQuantityTypeIdentifierDistanceCycling',
'startDate': new Date(), // mandatory
'endDate': null, // optional, use either this or duration
'duration': 3600, // in seconds, optional, use either this or endDate
'energy': 300, //
'energyUnit': 'kcal', // J|cal|kcal
'distance': 11, // optional
'distanceUnit': 'km' // probably useful with the former param
// 'extraData': "", // Not sure how necessary this is
},
console.log('success!!!!'),
console.log('ERRORR')
);
Hi, I've just updated the plugin. It now configures the entitlement when installing the plugin. That should fix your trouble next time.
Thanks for reporting this!
Hi!
I manage to check if HealthKit is available, but the request permission funtion won't fire a permission dialog on the users device. Also, when trying to add a new workout without permissions nothing happens....
Any thoughts?
This is my code: