I am using Ionic React to build an application that communicates to the fitness data of the user using the ionic Cordova health plugin, but does not seems to work.
import { Health } from "@ionic-native/health/ngx";
const Tab1: React.FC = () => {
let health = new Health();
const healtChanger = () => {
health.isAvailable()
.then((available:boolean) => {
console.log(health.isAuthorized(['steps']));
if(health.isAuthorized(['steps']))
{
console.log("Already Authorised");
health.queryAggregated({
startDate: new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000), // three days ago
endDate: new Date(), // now
dataType: 'steps',
bucket: 'day'
})
.then(res => console.log(res))
.catch(e => console.log(e));
}
else {
health.requestAuthorization([
'distance', 'nutrition', //read and write permissions
{
read: ['steps'], //read only permission
}
])
.then(res => console.log(res))
.catch(e => console.log(e));
}
})
.catch(e => console.log(e));
};
The code seems to have authorisation but when I try execution it gives an error cannot connect to google fit
. The output in chrome inspect for android device is as follows:
main.871c1aec.chunk.js:1 Promise {<pending>}
main.871c1aec.chunk.js:1 Already Authorised
main.871c1aec.chunk.js:1 Cannot connect to Google Fit
Any help shall be greatly appreciated.