离子健康插件无法连接到Google Fit
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了离子健康插件无法连接到Google Fit相关的知识,希望对你有一定的参考价值。
我正在使用Ionic React构建一个应用程序,该应用程序使用离子Cordova健康状况插件与用户的健身数据进行通信,但似乎无法正常工作。
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));
};
该代码似乎具有授权,但是当我尝试执行时,它给出了错误cannot connect to google fit
。 chrome inspect for android device的输出如下:
main.871c1aec.chunk.js:1 Promise {<pending>}
main.871c1aec.chunk.js:1 Already Authorised
main.871c1aec.chunk.js:1 Cannot connect to Google Fit
任何帮助都将不胜感激。
答案
if (health.isAuthorized(["steps"])) {
console.log("Already Authorised");
health.requestAuthorization([
"distance",
"nutrition",
{
read: ["steps", "height", "weight"],
write: ["height", "weight"],
},
])
.then((res) => console.log("response " + res))
.catch((e) => console.log("error " + e));
health.queryAggregated({
startDate: new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000),
endDate: new Date(), // now
dataType: 'steps',
bucket: 'day'
})
.then(res => console.log(res))
.catch(e => console.log(e));
} else {
health
.requestAuthorization([
"distance",
"nutrition",
{
read: ["steps"],
write: ["height", "weight"],
},
])
.then((res) => console.log(res))
.catch((e) => console.log(e));
}
})
.catch((e) => console.log(e));
};
以上是关于离子健康插件无法连接到Google Fit的主要内容,如果未能解决你的问题,请参考以下文章
为啥在 iOS 上运行的空白离子电容器应用程序返回此错误:无法连接到服务器
无需 oAuth 即可连接到非 Google 服务的 Gmail 插件
使用串行插件时出现 Ionic Capacitor Android 错误 - 连接到外部设备时出现 Cordova_not_available
设置 Github Jenkins 插件时出现“无法连接到存储库”错误