This sample shows a simple use of the iOS HealthKit APIs.
It is a very simple scenario but should help you out to get started if you want to work with this SDK. The most important part of the sample is located in main.js file. Here is a snippet of code used to initialize the HealthKit SDK
if (HKHealthStore.isHealthDataAvailable()) {
var weightType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass);
var writeDataTypes = NSSet.setWithObject(weightType);
var readDataTypes = NSSet.setWithObject(weightType);
var healthStore = HKHealthStore.new();
healthStore.requestAuthorizationToShareTypesReadTypesCompletion(readDataTypes, readDataTypes, function (success, error) {
if (!success) {
...
To run this example you must enable HealthKit in you xCode project:
- Add iOS platform to the application running the command: tns platform add ios
- Copy the NativeScript project files to the Xcode project that was created for the iOS platform running the command: tns prepare ios (needed only if you want to run the app from Xcode (step 5))
- Open the Xcode project file .xcodeproject (--MyNativeScriptProjectFolder--/platforms/iOS) in Xcode.
- Follow the steps from Adding Capabilities article to add HealthKit.
- Run the project from Xcode or run the following command: tns run ios --emulator to check how the project works.
If you have any questions about the sample please open an issue in our issues repo or post directly in NativeScript forums.