离子健康插件无法连接到Google Fit

问题描述 投票:0回答:1

我正在使用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

任何帮助都将不胜感激。

reactjs cordova ionic4 ionic-react
1个回答
0
投票
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)); };
© www.soinside.com 2019 - 2024. All rights reserved.