dariosalvi78 / cordova-plugin-health

Cordova plugin for the HealthKit and Google Fit frameworks
MIT License
176 stars 127 forks source link

requestAuthorization Error #341

Open hamjad-centenum opened 2 days ago

hamjad-centenum commented 2 days ago

I could use your help. requestAuthorization returning Cannot read request objectValue ["steps","distance","calories"] at 0 of type org.json.JSONArray cannot be converted to JSONObject . Do you have an idea why this could be happening ?

Here is my implementation

  function onSuccess(authResult) {
      console.log("Authorization granted", authResult);
   }

    function onErr(error) {
      console.error("Authorization denied", error);
    }

    await cordova.plugins.health.requestAuthorization(
      ['steps', 'distance', 'calories'],
      onSuccess,
      onErr
    );
jammie27 commented 1 day ago

May i ask, do you build cordova project or capacitor project? Because i can't compile capacitor project at all.

hamjad-centenum commented 1 day ago

May i ask, do you build cordova project or capacitor project? Because i can't compile capacitor project at all.

Capacitor

jammie27 commented 1 day ago

I added plugin via npm as usual, try to use cordova.plugins.health (should be available globally), then ionic build , and get error, cordova is not defined. What can i miss? If i understand it, i can maybe come near to your case.

hamjad-centenum commented 1 day ago

I added plugin via npm as usual, try to use cordova.plugins.health (should be available globally), then ionic build , and get error, cordova is not defined. What can i miss? If i understand it, i can maybe come near to your case.

can you share your code?

jammie27 commented 1 day ago

Very simply, in component const res = await cordova.plugins.health.isAvailable();

And it causes compiling error error TS2304: Cannot find name 'cordova'.

Have i to import anything in component?

hamjad-centenum commented 1 day ago

Very simply, in component const res = await cordova.plugins.health.isAvailable();

And it causes compiling error error TS2304: Cannot find name 'cordova'.

Have i to import anything in component?

No you do not have to import anything, cordova.plugins.health is exposed globally at build time. what framework are you working with

jammie27 commented 1 day ago

i work with ionic / angular (standalone components).

hamjad-centenum commented 15 hours ago

i work with ionic / angular (standalone components).

oh i typically do not use angular but maybe you should create a private function in a service then import that into your component