2017-06-20 49 views
0

由於這是沒有nativeScript支持與ios HealthKit ..我正在嘗試使用api。如何使用api從angular2 nativescript獲取isHealthDataAvailable

要開始,我試圖讓一個簡單的布爾爲isHealthDataAvailable():

如何? declare 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. 

我求求不同...

+0

花花公子在nativescript.are你在那裏可以找到?您更喜歡使用stackoverflow,但您似乎對評論您的框架感興趣。它變得越來越明顯,使用nativescript還沒有準備好黃金時段。您的文檔已過時 – Tampa

回答

0

這是不是哪裏HKHealthStore生活,請參閱我的回答您的其他問題,我建議您安裝平臺聲明(npm i tns-platform-declarations --save-dev)。這將極大地幫助你:nativescript, angular2 and heaththkit - HKHealthStore not found;

要回答這個問題:它應該是HKHealthStore.isHealthDataAvailable()如可以在下面的截圖中可以看到(這是前述的那些打字稿聲明適用於iOS的代碼段:

enter image description here

+0

tns-platform-declarations does not work ...我無法做var healthStore:HKHealthStore; ---> [ts]找不到名字'HKHealthStore'。 – Tampa

+0

版本已安裝 - [email protected] – Tampa

0

您將需要使用數據轉換的正確語法描述(Objective-C的蘋果API和JavaScript)here

一步解釋
var healthStore = HKHealthStore.new(); 

大詳細步驟可以在this blog post

相關問題