cordova 如何解决离子血压计和保健仪的血压查询问题

vu8f3i0k  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(145)

我正在设置一个Ionic V4应用程序,并试图在图表中可视化收缩压和舒张压。因此,我尝试使用health-kit,通过链接https://github.com/dariosalvi78/cordova-plugin-health向我的Apple Health应用程序进行查询。
到目前为止,对于步骤、活动、大小和所有的东西,查询都工作得很好,但是对于血压就不工作了。下面是我的构造函数,它从加载页面开始进行身份验证:
构造函数(私有healthKit:HealthKit,私人平板电脑:平台){

this.plt.ready().then(() => {
  console.log('platform ready');
  this.healthKit.available().then(available => {
    console.log('health kit ready: ', available);
    if (available) {
      // Request all permissions up front if you like to
      const options: HealthKitOptions = {
        readTypes: [
            'HKQuantityTypeIdentifierBloodPressureSystolic',
            'HKQuantityTypeIdentifierBloodPressureDiastolic',
          ],
        writeTypes: [
          'HKQuantityTypeIdentifierBloodPressureSystolic',
          'HKQuantityTypeIdentifierBloodPressureDiastolic',
        ]
      }
      this.healthKit.requestAuthorization(options).then(_ => {
        this.loadHealthData();
      });
    }
  });
});

}
函数loadHealthData在对健康应用程序的查询进行身份验证后启动:

loadHealthData() {

const bloodPressureOptions = {
      startDate: new Date(new Date().getTime() - 24 * 60 * 60 * 1000), 
      endDate: new Date(),
      correlationType: 'HKCorrelationTypeIdentifierBloodPressure',
      unit: 'mmHg'
    }
    this.healthKit.queryCorrelationType(bloodPressureOptions
    ).then( value => {
      console.log('blood pressure data: ', value);
    }, err => {
      console.log('error getting blood pressure: ', err);
    });
}

遗憾的是,虽然我的健康应用程序中有许多血压数据,但记录的值始终为空。当我将“HKCorrelationTypeIdentifierBloodPressure”添加到读取权限时,我收到一个错误,提示无法授权。因此,我可以通过获取收缩压和舒张压的权限并与这两个权限进行关联来进行读取。我也尝试过只对收缩压和舒张压进行sampleQuery,但那里的响应也是空的。此外,我发现在我的健康应用程序中,我自己的应用程序没有列在血压的权限中,但我对此一无所知。
我真的很感激任何帮助这个问题!

s71maibg

s71maibg1#

我尝试使用下面的代码。

constructor(
    private healthKit: HealthKit,
    private platform: Platform,
    private zone: NgZone
  ) {
    platform.ready().then(() => {
      this.platform.resume.subscribe(async () => {
        await this.test();
      });
    });
  }

async test() {
    this.healthKit.available().then((available) => {
      if (available) {
        const options: HealthKitOptions = {
          readTypes: [ 'HKQuantityTypeIdentifierBloodPressureSystolic',
            'HKQuantityTypeIdentifierBloodPressureDiastolic']
 };
        this.healthKit.requestAuthorization(options).then((_) => {
          this.loadHealthData();
        });
      }
    });
  }

loadHealthData(){
const bloodPressureOptions = {
      startDate: new Date(new Date().getTime() - 30 * 24 * 60 * 60 * 1000),
      endDate: new Date(),
      correlationType: 'HKCorrelationTypeIdentifierBloodPressure',
      unit: 'mmHg'
    }
    this.healthKit.queryCorrelationType(bloodPressureOptions
    ).then(data => {
      this.zone.run(() => {
        console.log(data)
       }
      )
    })
}

上面的代码返回以下日志:

[log] - [{"metadata":{"HKWasUserEntered":1},"samples":[{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureSystolic","endDate":"2022-06-03T13:02:00+05:30","startDate":"2022-06-03T13:02:00+05:30","UUID":"0B7BAD5A-3A54-4680-85E0-13B92AAE01D3","value":200,"metadata":{"HKWasUserEntered":1}},{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureDiastolic","endDate":"2022-06-03T13:02:00+05:30","startDate":"2022-06-03T13:02:00+05:30","UUID":"2CD76ADC-2C33-42A9-804B-EB0B4B6927F1","value":100,"metadata":{"HKWasUserEntered":1}}],"endDate":"2022-06-03T13:02:00+05:30","startDate":"2022-06-03T13:02:00+05:30","UUID":"384254F3-81EC-4B3C-877B-00F19EAAAB3B","correlationType":"HKCorrelationTypeIdentifierBloodPressure"},{"metadata":{"HKWasUserEntered":1},"samples":[{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureSystolic","endDate":"2022-06-05T12:21:00+05:30","startDate":"2022-06-05T12:21:00+05:30","UUID":"53136DF5-9190-4401-B599-94EDFA6204CD","value":100,"metadata":{"HKWasUserEntered":1}},{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureDiastolic","endDate":"2022-06-05T12:21:00+05:30","startDate":"2022-06-05T12:21:00+05:30","UUID":"14632D4C-8D32-4D2E-9420-4E4FA73CC951","value":100,"metadata":{"HKWasUserEntered":1}}],"endDate":"2022-06-05T12:21:00+05:30","startDate":"2022-06-05T12:21:00+05:30","UUID":"3B0F0434-83CC-41D2-955F-9F1195D7D3CF","correlationType":"HKCorrelationTypeIdentifierBloodPressure"},{"metadata":{"HKWasUserEntered":1},"samples":[{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureDiastolic","endDate":"2022-06-05T18:54:00+05:30","startDate":"2022-06-05T18:54:00+05:30","UUID":"EBDC9CF9-D273-4439-9A4B-3C92B692D377","value":100,"metadata":{"HKWasUserEntered":1}},{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureSystolic","endDate":"2022-06-05T18:54:00+05:30","startDate":"2022-06-05T18:54:00+05:30","UUID":"0679C83C-2089-491D-B482-F95453F41824","value":110,"metadata":{"HKWasUserEntered":1}}],"endDate":"2022-06-05T18:54:00+05:30","startDate":"2022-06-05T18:54:00+05:30","UUID":"32CC62C0-E5B0-48B0-AEA7-0F5FA4D72E6B","correlationType":"HKCorrelationTypeIdentifierBloodPressure"},{"metadata":{"HKWasUserEntered":1},"samples":[{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureSystolic","endDate":"2022-06-06T10:26:00+05:30","startDate":"2022-06-06T10:26:00+05:30","UUID":"88AAB09B-1F26-49CF-88D1-D7E5B5B4BE31","value":120,"metadata":{"HKWasUserEntered":1}},{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureDiastolic","endDate":"2022-06-06T10:26:00+05:30","startDate":"2022-06-06T10:26:00+05:30","UUID":"6BD456A5-EE3F-426E-A34B-66AA774FBEB5","value":100,"metadata":{"HKWasUserEntered":1}}],"endDate":"2022-06-06T10:26:00+05:30","startDate":"2022-06-06T10:26:00+05:30","UUID":"DA3F0EAC-B325-4916-B9CD-A4FAFBD5C508","correlationType":"HKCorrelationTypeIdentifierBloodPressure"},{"metadata":{"HKWasUserEntered":1},"samples":[{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureSystolic","endDate":"2022-06-06T10:45:00+05:30","startDate":"2022-06-06T10:45:00+05:30","UUID":"7E8157F0-6051-42F7-ACA2-F47B51C3638A","value":125,"metadata":{"HKWasUserEntered":1}},{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureDiastolic","endDate":"2022-06-06T10:45:00+05:30","startDate":"2022-06-06T10:45:00+05:30","UUID":"5FEE364B-3EBB-4B12-A07D-8D8BE0897F50","value":105,"metadata":{"HKWasUserEntered":1}}],"endDate":"2022-06-06T10:45:00+05:30","startDate":"2022-06-06T10:45:00+05:30","UUID":"3C32FBB4-C432-4119-895A-05E3AA9CFCB4","correlationType":"HKCorrelationTypeIdentifierBloodPressure"},{"metadata":{"HKWasUserEntered":1},"samples":[{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureDiastolic","endDate":"2022-06-06T10:49:00+05:30","startDate":"2022-06-06T10:49:00+05:30","UUID":"380F2276-E980-476D-9D29-618FC2E332A4","value":120,"metadata":{"HKWasUserEntered":1}},{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureSystolic","endDate":"2022-06-06T10:49:00+05:30","startDate":"2022-06-06T10:49:00+05:30","UUID":"C458EAF5-9342-4963-B2C5-65D52E94760D","value":120,"metadata":{"HKWasUserEntered":1}}],"endDate":"2022-06-06T10:49:00+05:30","startDate":"2022-06-06T10:49:00+05:30","UUID":"87845254-3483-46F1-908E-10D34253BF24","correlationType":"HKCorrelationTypeIdentifierBloodPressure"},{"metadata":{"HKWasUserEntered":1},"samples":[{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureSystolic","endDate":"2022-06-07T11:49:00+05:30","startDate":"2022-06-07T11:49:00+05:30","UUID":"4D437E52-AC2C-4C16-85FE-ECA34F8D4717","value":111,"metadata":{"HKWasUserEntered":1}},{"unit":"mmHg","sampleType":"HKQuantityTypeIdentifierBloodPressureDiastolic","endDate":"2022-06-07T11:49:00+05:30","startDate":"2022-06-07T11:49:00+05:30","UUID":"30DB0A7B-ACEB-43E8-B94B-3739A30716C6","value":110,"metadata":{"HKWasUserEntered":1}}],"endDate":"2022-06-07T11:49:00+05:30","startDate":"2022-06-07T11:49:00+05:30","UUID":"6B8CF463-A314-42F5-B41C-561F1D93AB58","correlationType":"HKCorrelationTypeIdentifierBloodPressure"}]

我已经使用ngZone动态更新应用程序上的值,如果健康应用程序上的数据发生变化。如果有任何疑问,请告诉我,我将很乐意提供帮助。

相关问题