From 44957e2197f8bf1403bc559445c16966b2254adf Mon Sep 17 00:00:00 2001 From: Ankush Aggarwal Date: Tue, 11 Apr 2017 09:39:24 -0700 Subject: [PATCH 1/3] Update datatypes to match recent release of plugin I made changes to cordova-plugin-health to accept the following array as datatypes. Earlier it was just an array of strings. Now it also contains an object with `read` and `write` array. ``` [ 'calories', 'distance', //read and write permissions { read : ['steps'], //read only permission write : ['height', 'weight'] //write only permission } ] ``` Don't know how to specify this array in typescript so just replaced by 'any' --- src/@ionic-native/plugins/health/index.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/@ionic-native/plugins/health/index.ts b/src/@ionic-native/plugins/health/index.ts index 06896be14..ed54ead6c 100644 --- a/src/@ionic-native/plugins/health/index.ts +++ b/src/@ionic-native/plugins/health/index.ts @@ -219,22 +219,32 @@ export class Health { * In Android 6 and over, this function will also ask for some dynamic permissions if needed * (e.g. in the case of "distance", it will need access to ACCESS_FINE_LOCATION). * - * @param {Array} datatypes a list of data types you want to be granted access to + * @param {Array} datatypes a list of data types you want to be granted access to. * + * ``` + * [ + * 'calories', 'distance', //read and write permissions + * { + * read : ['steps'], //read only permission + * write : ['height', 'weight'] //write only permission + * } + * ] + * ``` + * * @return {Promise} */ @Cordova() - requestAuthorization(datatypes: Array): Promise { return; } + requestAuthorization(datatypes: Array): Promise { return; } /** * Check if the app has authorization to read/write a set of datatypes. * This function is similar to requestAuthorization() and has similar quirks. * - * @param {Array} datatypes a list of data types you want to be granted access to + * @param {Array} datatypes a list of data types you want to be granted access to * @return {Promise} Returns a promise that resolves with a boolean that indicates the authorization status */ @Cordova() - isAuthorized(datatypes: Array): Promise { return; } + isAuthorized(datatypes: Array): Promise { return; } /** * Gets all the data points of a certain data type within a certain time window. From 43b75af58bc718c46a5cd412af498a68335b8f16 Mon Sep 17 00:00:00 2001 From: Ankush Aggarwal Date: Thu, 13 Apr 2017 17:56:59 -0700 Subject: [PATCH 2/3] changed any to specific types --- src/@ionic-native/plugins/health/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/@ionic-native/plugins/health/index.ts b/src/@ionic-native/plugins/health/index.ts index ed54ead6c..acfa5a4e2 100644 --- a/src/@ionic-native/plugins/health/index.ts +++ b/src/@ionic-native/plugins/health/index.ts @@ -219,7 +219,7 @@ export class Health { * In Android 6 and over, this function will also ask for some dynamic permissions if needed * (e.g. in the case of "distance", it will need access to ACCESS_FINE_LOCATION). * - * @param {Array} datatypes a list of data types you want to be granted access to. + * @param {(string|{ read: string[], write: string[] })[]} datatypes a list of data types you want to be granted access to. * * ``` * [ @@ -234,17 +234,17 @@ export class Health { * @return {Promise} */ @Cordova() - requestAuthorization(datatypes: Array): Promise { return; } + requestAuthorization(datatypes: (string|{ read: string[], write: string[] })[]): Promise { return; } /** * Check if the app has authorization to read/write a set of datatypes. * This function is similar to requestAuthorization() and has similar quirks. * - * @param {Array} datatypes a list of data types you want to be granted access to + * @param {(string|{ read: string[], write: string[] })[]} datatypes a list of data types you want to check access of, same as in requestAuthorization * @return {Promise} Returns a promise that resolves with a boolean that indicates the authorization status */ @Cordova() - isAuthorized(datatypes: Array): Promise { return; } + isAuthorized(datatypes: (string|{ read: string[], write: string[] })[]): Promise { return; } /** * Gets all the data points of a certain data type within a certain time window. From 1da12b9330e41c5624d39f19a1bf97251d6f9882 Mon Sep 17 00:00:00 2001 From: Ankush Aggarwal Date: Fri, 14 Apr 2017 08:21:45 -0700 Subject: [PATCH 3/3] added HealthDataType interface and usage instructions --- src/@ionic-native/plugins/health/index.ts | 54 +++++++++++++++-------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/@ionic-native/plugins/health/index.ts b/src/@ionic-native/plugins/health/index.ts index acfa5a4e2..cdee113ec 100644 --- a/src/@ionic-native/plugins/health/index.ts +++ b/src/@ionic-native/plugins/health/index.ts @@ -1,6 +1,21 @@ import { Plugin, Cordova } from '@ionic-native/core'; import { Injectable } from '@angular/core'; +/** + * @hidden + */ +export interface HealthDataType { + /** + * Read only date types (see https://github.com/dariosalvi78/cordova-plugin-health#supported-data-types) + */ + read?: string[]; + + /** + * Write only date types (see https://github.com/dariosalvi78/cordova-plugin-health#supported-data-types) + */ + write?: string[]; +} + /** * @hidden */ @@ -154,9 +169,19 @@ export interface HealthData { * ... * * this.health.isAvailable() + * .then((available:boolean) => { + * console.log(available); + * this.health.requestAuthorization([ + * 'distance', 'nutrition', //read and write permissions + * { + * read: ['steps'], //read only permission + * write: ['height', 'weight'] //write only permission + * } + * ]) * .then(res => console.log(res)) * .catch(e => console.log(e)); - * + * }) + * .catch(e => console.log(e)); * * ``` * See description at https://github.com/dariosalvi78/cordova-plugin-health for a full list of Datatypes and see examples. @@ -204,7 +229,7 @@ export class Health { promptInstallFit(): Promise { return; } /** - * Requests read and write access to a set of data types. It is recommendable to always explain why the app + * Requests read and/or write access to a set of data types. It is recommendable to always explain why the app * needs access to the data before asking the user to authorize it. * This function must be called before using the query and store functions, even if the authorization has already * been given at some point in the past. @@ -219,32 +244,25 @@ export class Health { * In Android 6 and over, this function will also ask for some dynamic permissions if needed * (e.g. in the case of "distance", it will need access to ACCESS_FINE_LOCATION). * - * @param {(string|{ read: string[], write: string[] })[]} datatypes a list of data types you want to be granted access to. - * - * ``` - * [ - * 'calories', 'distance', //read and write permissions - * { - * read : ['steps'], //read only permission - * write : ['height', 'weight'] //write only permission - * } - * ] - * ``` - * + * @param {Array} datatypes a list of data types you want to be granted access to. * @return {Promise} */ @Cordova() - requestAuthorization(datatypes: (string|{ read: string[], write: string[] })[]): Promise { return; } + requestAuthorization(datatypes: Array): Promise { return; } /** * Check if the app has authorization to read/write a set of datatypes. - * This function is similar to requestAuthorization() and has similar quirks. * - * @param {(string|{ read: string[], write: string[] })[]} datatypes a list of data types you want to check access of, same as in requestAuthorization + * Quirks of isAuthorized() + * + * In iOS, this function will only check authorization status for writeable data. + * Read-only data will always be considered as not authorized. This is an intended behaviour of HealthKit. + * + * @param {Array} datatypes a list of data types you want to check access of, same as in requestAuthorization * @return {Promise} Returns a promise that resolves with a boolean that indicates the authorization status */ @Cordova() - isAuthorized(datatypes: (string|{ read: string[], write: string[] })[]): Promise { return; } + isAuthorized(datatypes: Array): Promise { return; } /** * Gets all the data points of a certain data type within a certain time window.