【问题标题】:How to get isHealthDataAvailable from angular2 nativescript using api如何使用 api 从 angular2 nativescript 获取 isHealthDataAvailable
【发布时间】:2017-06-23 09:56:28
【问题描述】:

由于 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.

我请求不同...

【问题讨论】:

  • nativescript 的伙计们。你们在吗?您更喜欢 stackoverflow,但您似乎对评论您的框架不感兴趣。越来越明显的是,nativescript 的使用还没有为黄金时段做好准备。您的文档已过期

标签: nativescript angular2-nativescript


【解决方案1】:

这不是HKHealthStore 所在的地方,请参阅我对您的其他问题的回答,我建议您安装平台声明 (npm i tns-platform-declarations --save-dev)。它将极大地帮助您:nativescript, angular2 and heaththkit - HKHealthStore not found;

要回答这个问题:应该是HKHealthStore.isHealthDataAvailable(),如下面的截图所示(这是前面提到的 iOS 的 TypeScript 声明的 sn-p:

【讨论】:

  • tns-platform-declarations 不起作用...我不能做 var healthStore: HKHealthStore; ---> [ts] 找不到名称“HKHealthStore”。
  • 已安装版本 - tns-platform-declarations@3.0.1
【解决方案2】:

您需要使用正确的语法进行数据转换(在 Objective-C Apple API 和 JavaScript 之间),如 here 所述

例如

var healthStore = HKHealthStore.new();

详细的分步说明可以在this blog post找到

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    相关资源
    最近更新 更多