{"id":15193870,"url":"https://github.com/nativescript-community/nativescript-health-data","last_synced_at":"2025-10-27T20:31:02.474Z","repository":{"id":43255571,"uuid":"99260198","full_name":"nativescript-community/nativescript-health-data","owner":"nativescript-community","description":"Cross platform Health Plugin for NativeScript, using Apple HealthKit and Google Fit","archived":false,"fork":false,"pushed_at":"2024-05-08T20:49:48.000Z","size":40017,"stargazers_count":48,"open_issues_count":13,"forks_count":17,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-08-09T11:45:25.435Z","etag":null,"topics":["google-fit","health","healthkit","nativescript","nativescript-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nativescript-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-03T17:49:59.000Z","updated_at":"2024-10-05T15:31:56.000Z","dependencies_parsed_at":"2024-06-21T04:20:30.990Z","dependency_job_id":"7ceedf62-132c-48a0-8606-9b40a9b9e6e4","html_url":"https://github.com/nativescript-community/nativescript-health-data","commit_stats":null,"previous_names":["filipemendes1994/nativescript-health-data"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/nativescript-community/nativescript-health-data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativescript-community%2Fnativescript-health-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativescript-community%2Fnativescript-health-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativescript-community%2Fnativescript-health-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativescript-community%2Fnativescript-health-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nativescript-community","download_url":"https://codeload.github.com/nativescript-community/nativescript-health-data/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativescript-community%2Fnativescript-health-data/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281336627,"owners_count":26483860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-fit","health","healthkit","nativescript","nativescript-plugin"],"created_at":"2024-09-27T22:06:26.733Z","updated_at":"2025-10-27T20:31:02.098Z","avatar_url":"https://github.com/nativescript-community.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./images/healthkit-googlefit.jpg\" height=\"200px\" /\u003e\n\u003c/p\u003e\n\n# Health Data plugin for NativeScript\n\nThis is a NativeScript plugin that abstracts Apple HealthKit and Google Fit to read health data from the user's device.\n\n[![Build Status][build-status]][build-url]\n[![NPM version][npm-image]][npm-url]\n[![Downloads][downloads-image]][npm-url]\n[![Twitter Follow][twitter-image]][twitter-url]\n\n[build-status]: https://travis-ci.org/EddyVerbruggen/nativescript-health-data.svg?branch=master\n[build-url]: https://travis-ci.org/EddyVerbruggen/nativescript-health-data\n[npm-image]: http://img.shields.io/npm/v/nativescript-health-data.svg\n[npm-url]: https://npmjs.org/package/nativescript-health-data\n[downloads-image]: http://img.shields.io/npm/dm/nativescript-health-data.svg\n[twitter-image]: https://img.shields.io/twitter/follow/eddyverbruggen.svg?style=social\u0026label=Follow%20me\n[twitter-url]: https://twitter.com/eddyverbruggen\n\n## Prerequisites\n\n### Android\n\nGoogle Fit API Key - Go to the [Google Developers Console](https://console.developers.google.com/), create a project, and enable the `Fitness API`.\nThen under `Credentials`, create a `Fitness API` OAuth2 client ID for an Android App (select `User data` and press the `What credentials do I need?` button).\nIf you are using Linux/maxOS, generate your SHA1-key with the code below.\n\n```shell\nkeytool -exportcert -keystore path-to-debug-or-production-keystore -list -v\n```\n\n\u003e Note that the default (debug) keystore password is empty.\n\n### iOS\n\nMake sure you enable the `HealthKit` entitlement in your app ID.\n\n## Installation\n\nInstall the plugin using the NativeScript CLI:\n\n```\ntns plugin add nativescript-health-data\n```\n\n## API\n\nThe examples below are all in TypeScript, and the [demo](https://github.com/EddyVerbruggen/nativescript-health-data/tree/master/demo-ng) was developed in Nativescript w/ Angular.\n\nThis is how you can import and instantiate the plugin, all examples expect this setup:\n\n```typescript\nimport { AggregateBy, HealthData, HealthDataType } from 'nativescript-health-data';\n\nexport class MyHealthyClass {\n\tprivate healthData: HealthData;\n\n\tconstructor() {\n\t\tthis.healthData = new HealthData();\n\t}\n}\n```\n\n### `isAvailable`\n\nThis tells you whether or not the device supports Health Data. On iOS this is probably always `true`.\nOn Android the user will be prompted to (automatically) update their Play Services version in case it's not sufficiently up to date.\nIf you don't want this behavior, pass false to this function, as shown below.\n\n```typescript\nthis.healthData.isAvailable(false).then((available) =\u003e console.log(available));\n```\n\n### `isAuthorized`\n\nThis function (and the next one) takes an `Array` of `HealthDataType`'s. Each of those has a `name` and an `accessType`.\n\n-   The `name` can be one of the ['Available Data Types'](#available-data-types).\n-   The accessType can be one of `read`, `write`, or `readAndWrite` (note that this plugin currently only supports reading data, but that will change).\n\n\u003e iOS is a bit silly here: if you've only requested 'read' access, you'll never get a `true` response from this method. [Details here.](https://stackoverflow.com/a/29128231/2596974)\n\n```typescript\nthis.healthData\n\t.isAuthorized([\u003cHealthDataType\u003e{ name: 'steps', accessType: 'read' }])\n\t.then((authorized) =\u003e console.log(authorized));\n```\n\n### `requestAuthorization`\n\nThis function takes the same argument as `isAuthorized`, and will trigger a consent screen in case the user hasn't previously authorized your app to access any of the passed `HealthDataType`'s.\n\nNote that this plugin currently only supports reading data, but that will change.\n\n```typescript\nconst types: Array\u003cHealthDataType\u003e = [\n\t{ name: 'height', accessType: 'write' },\n\t{ name: 'weight', accessType: 'readAndWrite' },\n\t{ name: 'steps', accessType: 'read' },\n\t{ name: 'distance', accessType: 'read' },\n];\n\nthis.healthData\n\t.requestAuthorization(types)\n\t.then((authorized) =\u003e console.log(authorized))\n\t.catch((error) =\u003e console.log('Request auth error: ', error));\n```\n\n### `query`\n\nMandatory properties are `startData`, `endDate`, and `dataType`.\nThe `dataType` must be one of the ['Available Data Types'](#available-data-types).\n\nBy default data is not aggregated, so all individual datapoints are returned.\nThis plugin however offers a way to aggregate the data by either `hour`, `day`, or `sourceAndDay`,\nthe latter will enable you to read daily data per source (Fitbit, Nike Run Club, manual entry, etc).\n\nIf you didn't run `requestAuthorization` before running `query`,\nthe plugin will run `requestAuthorization` for you (for the requested `dataType`). You're welcome. 😉\n\n```typescript\nthis.healthData\n\t.query({\n\t\tstartDate: new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000), // 3 days ago\n\t\tendDate: new Date(), // now\n\t\tdataType: 'steps', // equal to the 'name' property of 'HealthDataType'\n\t\tunit: 'count', // make sure this is compatible with the 'dataType' (see below)\n\t\taggregateBy: 'day', // optional, one of: \"hour\", \"day\", \"sourceAndDay\"\n\t\tsortOrder: 'desc', // optional, default \"asc\"\n\t})\n\t.then((result) =\u003e console.log(JSON.stringify(result)))\n\t.catch((error) =\u003e (this.resultToShow = error));\n```\n\n### `queryAggregateData`\n\nDifference between `query` and `queryAggregateData`: if you use `query`, you will probably find that the number of steps (or other types of data) do not match those shown by the Google Fit and Apple Health apps. If you wanted to accurately compute the user's data then use: `queryAggregateData`\n\nMandatory properties are `startData`, `endDate`, and `dataType`.\nThe `dataType` must be one of the ['Available Data Types'](#available-data-types).\n\nBy default data is aggregated by `day`.\nThis plugin however offers a way to aggregate the data by either `hour` and `day`. (`month` and `year` available soon)\n\nNote that `queryAggregateData` only supports `steps`, `calories` and `distance` on Android. (More data types available soon).\n\nIf you didn't run `requestAuthorization` before running `query`,\nthe plugin will run `requestAuthorization` for you (for the requested `dataType`). You're welcome. 😉\n\n```typescript\nthis.healthData\n\t.queryAggregateData({\n\t\tstartDate: new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000), // 3 days ago\n\t\tendDate: new Date(), // now\n\t\tdataType: 'steps', // equal to the 'name' property of 'HealthDataType'\n\t\tunit: 'count', // make sure this is compatible with the 'dataType' (see below)\n\t\taggregateBy: 'day', // optional, one of: \"hour\", \"day\" ; default: \"day\"\n\t})\n\t.then((result) =\u003e console.log(JSON.stringify(result)))\n\t.catch((error) =\u003e (this.resultToShow = error));\n```\n\n### `startMonitoring` (iOS only, for now)\n\nIf you want to be notified when health data was changed, you can monitor specific types.\nThis even works when your app is in the background, with `enableBackgroundUpdates: true`.\nNote that iOS will wake up your app so you can act upon this notification (in the `onUpdate` function by fi. querying recent changes to this data type),\nbut in return you are responsible for telling iOS you're done. So make sure you invoke the `completionHandler` as shown below.\n\nNot all data types support `backgroundUpdateFrequency: \"immediate\"`,\nso your app may not always be invoked immediately when data is added/deleted in HealthKit.\n\n\u003e Background notifications probably don't work on the iOS simulator, so please test those on a real device.\n\n```typescript\nthis.healthData\n\t.startMonitoring({\n\t\tdataType: 'heartRate',\n\t\tenableBackgroundUpdates: true,\n\t\tbackgroundUpdateFrequency: 'immediate',\n\t\tonUpdate: (completionHandler: () =\u003e void) =\u003e {\n\t\t\tconsole.log('Our app was notified that health data changed, so querying...');\n\t\t\tthis.getData('heartRate', 'count/min').then(() =\u003e completionHandler());\n\t\t},\n\t})\n\t.then(() =\u003e (this.resultToShow = `Started monitoring heartRate`))\n\t.catch((error) =\u003e (this.resultToShow = error));\n```\n\n### `stopMonitoring` (iOS only, for now)\n\nIt's best to call this method in case you no longer wish to receive notifications when health data changes.\n\n```typescript\nthis.healthData\n\t.stopMonitoring({\n\t\tdataType: 'heartRate',\n\t})\n\t.then(() =\u003e (this.resultToShow = `Stopped monitoring heartRate`))\n\t.catch((error) =\u003e (this.resultToShow = error));\n```\n\n## Available Data Types\n\nWith version 1.0.0 these are the supported types of data you can read. Also, make sure you pass in the correct `unit`.\n\nNote that you are responsible for passing the correct `unit`, although there's only 1 option for each type. _Well actually, the `unit` is ignored on Android at the moment, and on iOS there are undocumented types you can pass in (fi. `mi` for `distance`)._\n\nThe reason is I intend to support more units per type, but that is yet to be implemented... so it's for the sake of future backward-compatibility! 🤯\n\n| TypeOfData    | Unit      | GoogleFit Data Type        | Apple HealthKit Data Type                        |\n| ------------- | --------- | -------------------------- | ------------------------------------------------ |\n| distance      | m         | `TYPE_DISTANCE_DELTA`      | `HKQuantityTypeIdentifierDistanceWalkingRunning` |\n| steps         | count     | `TYPE_STEP_COUNT_DELTA`    | `HKQuantityTypeIdentifierStepCount`              |\n| calories      | count     | `TYPE_CALORIES_EXPENDED`   | `HKQuantityTypeIdentifierActiveEnergyBurned`     |\n| height        | m         | `TYPE_HEIGHT`              | `HKQuantityTypeIdentifierHeight`                 |\n| weight        | kg        | `TYPE_WEIGHT`              | `HKQuantityTypeIdentifierBodyMass`               |\n| heartRate     | count/min | `TYPE_HEART_RATE_BPM`      | `HKQuantityTypeIdentifierHeartRate`              |\n| fatPercentage | %         | `TYPE_BODY_FAT_PERCENTAGE` | `HKQuantityTypeIdentifierBodyFatPercentage`      |\n\n## Credits\n\n-   [Filipe Mendes](https://github.com/filipemendes1994/) for a superb first version of this repo, while working for SPMS, Shared Services for Ministry of Health (of Portugal). He kindly transferred this repo to me when he no longer had time to maintain it.\n-   Daniel Leal, for [a great PR](https://github.com/EddyVerbruggen/nativescript-health-data/pull/4).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnativescript-community%2Fnativescript-health-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnativescript-community%2Fnativescript-health-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnativescript-community%2Fnativescript-health-data/lists"}