我在Ionic应用程序上安装了此插件:https://ionicframework.com/docs/native/health/
此插件与Apple Health-Kit和Google-Fit兼容。这是我的代码:
import { Component } from '@angular/core';
import { NavController, IonicPage } from 'ionic-angular';
import { Health } from '@ionic-native/health';
@IonicPage({
priority: 'off'
})
@Component({
selector: 'page-health',
templateUrl: 'health.html'
})
export class HealthPage {
constructor(public navCtrl: NavController,
private health: Health) {
this.health.isAvailable()
.then((available:boolean) => {
console.log(available);
this.health.requestAuthorization([
'distance', 'nutrition', //read and write permissions
{
read: ['steps'], //read only permission
write: ['height', 'weight'] //write only permission
}])
.then(res => console.log(res))
.catch(e => console.log(e));
})
.catch(e => console.log(e));
}
}
当我在DevApp上运行它时,会收到以下警告(即使我安装了cordova和npm插件):
console.warn:Ionic Native:尝试调用Health.isAvailable,但是未安装Health插件。
console.warn:安装Health插件:“离子cordova插件添加cordova-plugin-health”
我在设备上使用Xcode运行了它,并且工作正常。但是我要做的是使用Ionic DevApp进行尝试,因为它可以快速进行编辑和开发。我检查了一下,DevApp支持此插件,因此应该没有问题。请参阅链接:https://ionicframework.com/docs/pro/devapp/
有什么想法吗?谢谢!