由于ios HealthKit不支持原生脚本,所以我正在尝试使用api。
首先,我尝试为isHealthDataAvailable()获得一个简单的布尔值:
多么?声明var NSBundle: any;
constructor() {
if (Platform.isIOS){
let healthStore = NSBundle.mainBundle.HKHealthStore();
let is_avail = healthStore.isHealthDataAvailable();
}
}
(in promise): TypeError: NSBundle.mainBundle.HKHealthStore is not a function. (In 'NSBundle.mainBundle.HKHealthStore()', 'NSBundle.mainBundle.HKHealthStore' is undefined)这是NativeScript的一句话:https://www.nativescript.org/blog/how-to-enable-healthkit-in-your-nativescript-application
var healthStore = HKHealthStore.new();
And this is how to use HealthKit API in NativeScript. Yes, it is THAT simple.我请求不同..。
发布于 2017-06-20 22:39:19
这不是HKHealthStore所在的地方,请参阅我对您的另一个问题的回答,我建议您在哪里安装平台声明(npm i tns-platform-declarations --save-dev)。它会给你带来极大的帮助:nativescript, angular2 and heaththkit - HKHealthStore not found;
要回答这个问题:它应该是HKHealthStore.isHealthDataAvailable(),如下面的截图所示(这是前面提到的iOS的TypeScript声明的一个片段:

发布于 2017-06-20 22:42:03
您需要使用正确的语法进行数据转换(在Objective-C Apple API和JavaScript之间),如here所述
例如:
var healthStore = HKHealthStore.new();可以在this blog post中找到详细的分步说明
https://stackoverflow.com/questions/44655801
复制相似问题