0
votes

Since that is no nativescript support with ios HealthKit..I am trying to work with the api.

To start I am trying to get a simple bool for isHealthDataAvailable():

How? 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)

This is a quote from 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.

I beg differ...

2
Dudes at nativescript.are you there? You prefer stackoverflow yet you do not seem interested in commenting on your framework. Its becoming increasing obvious that the use of nativescript is not ready for primetime. Your documentation is out of date - Tampa

2 Answers

0
votes

That's not where HKHealthStore lives, please see my answer to your other question where I suggest you install the platform declarations (npm i tns-platform-declarations --save-dev). It will help you tremendously: nativescript, angular2 and heaththkit - HKHealthStore not found;

To answer this question: it should be HKHealthStore.isHealthDataAvailable() as can be seen in the screenshot below (which is a snippet of those aforementioned TypeScript declarations for iOS:

enter image description here

0
votes

You will need to use the proper syntax for data conversion (between the Objective-C Apple API and JavaScript) as described here

e.g.

var healthStore = HKHealthStore.new();

Great detailed step by step explanation can be found in this blog post