dariosalvi78 / cordova-plugin-health

Cordova plugin for the HealthKit and Google Fit frameworks
MIT License
179 stars 128 forks source link

Something wrong with the requestAuth function after user revokes the permission from Apple Health (ios only) #126

Closed dopplerDistortion closed 5 years ago

dopplerDistortion commented 5 years ago

Hello there,

If user revokes the permissions from Apple Health we cant get any requestPrompt back. We are requesting the permission with this function on our register loop.

permHealth() { this.health .isAvailable() .then((available: boolean) => { console.log(available); this.health .requestAuthorization([ 'height', 'weight', 'blood_glucose', 'blood_pressure', 'steps' ]) .then((res) => { this.navCtrl.setRoot(GenderPage); }) .catch((e) => console.log(e)); }) .catch((e) => console.log(e)); }

After that we are controlling the request in a particular page with this function

permHealth() { this.health.isAuthorized([ 'height', 'weight', 'blood_glucose', 'blood_pressure', 'steps' ]).then((data)=>{ console.log(data); if(data == false){ this.health.requestAuthorization([ 'height', 'weight', 'blood_glucose', 'blood_pressure', 'steps' ]).then((res)=>{ console.log(res); }).catch((err)=>{ console.log(err); }); }else{ console.log("auths"); } });

If user revokes the permmissions second function is not prompting permission modal from Apple Health. err returns null and it is working on as expected on Android

my Ionic info

`Ionic:

ionic (Ionic CLI) : 4.3.1 Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : android 7.1.2, ios 4.5.5 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.3, (and 20 other plugins)

System:

Android SDK Tools : 26.1.1 (/Users/goksenin/Library/Android/sdk) ios-deploy : 1.9.4 NodeJS : v10.13.0 (/usr/local/bin/node) npm : 6.4.1 OS : macOS Xcode : Xcode 10.1 Build version 10B61`

dopplerDistortion commented 5 years ago

@dariosalvi78 did you have time for this issue. I need suggestions to fix this :/

ghost commented 5 years ago

let me try this use case on my phone and I'll let you know

dopplerDistortion commented 5 years ago

Ok thank you!

dopplerDistortion commented 5 years ago

let me try this use case on my phone and I'll let you know

any updates?

ghost commented 5 years ago

I'd love to give you some, but I'm lost in the stupid certificates. Again.

ghost commented 5 years ago

I've managed to execute the following test:

  1. start the app, debug it with Safari, from the console: navigator.health.requestAuthorization(['steps'], successCallback, errorCallback)
  2. allow all
  3. navigator.health.isAuthorized(['steps'], successCallback, errorCallback) -> answers: true
  4. stop the app
  5. go to Health App and revoke both read and write permissions on steps
  6. start the app again, call navigator.health.isAuthorized(['steps'], successCallback, errorCallback) -> answers: false

All as expected.

dopplerDistortion commented 5 years ago

This is ok for me too till 6th step. But after that I will add three more step for ios (no problem on android)

7- if the Auth is false health.requestAuthorization(['steps'], successCallback, errorCallback) 8- healthApp doesn't come up for reauthorization 9- succesCallback -> null

ghost commented 5 years ago

I see, I'll try again after the holidays...

dopplerDistortion commented 5 years ago

It appears to be a normal Health Kit behavior. It is explained under Discussion headline in the documentation link below. I think this information should be in your documentation also. This issue can be closed. Have a nice holiday!

https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization

ghost commented 5 years ago

thanks, this is very interesting...