diff --git a/RCTAppleHealthKit.xcodeproj/project.pbxproj b/RCTAppleHealthKit.xcodeproj/project.pbxproj index 247f7efe650ff9962bc5e3f520a89c7f0cc9eaab..0f9d512a7b3846fb76126d331d4754b013b40809 100644 --- a/RCTAppleHealthKit.xcodeproj/project.pbxproj +++ b/RCTAppleHealthKit.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 3774C8D71D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m in Sources */ = {isa = PBXBuildFile; fileRef = 3774C8D61D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m */; }; 377D44F31D247D0A004E35CB /* RCTAppleHealthKit+Methods_Characteristic.m in Sources */ = {isa = PBXBuildFile; fileRef = 377D44F21D247D0A004E35CB /* RCTAppleHealthKit+Methods_Characteristic.m */; }; 37837E7D1DCFE270000201A0 /* RCTAppleHealthKit+Methods_Sleep.m in Sources */ = {isa = PBXBuildFile; fileRef = 37837E7C1DCFE270000201A0 /* RCTAppleHealthKit+Methods_Sleep.m */; }; + 61232F931E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.m in Sources */ = {isa = PBXBuildFile; fileRef = 61232F921E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.m */; }; 64C42D4A1D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m in Sources */ = {isa = PBXBuildFile; fileRef = 64C42D491D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m */; }; 64E0E73F1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.m in Sources */ = {isa = PBXBuildFile; fileRef = 64E0E73E1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.m */; }; /* End PBXBuildFile section */ @@ -51,6 +52,8 @@ 377D44F21D247D0A004E35CB /* RCTAppleHealthKit+Methods_Characteristic.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Characteristic.m"; sourceTree = ""; }; 37837E7B1DCFE270000201A0 /* RCTAppleHealthKit+Methods_Sleep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Methods_Sleep.h"; sourceTree = ""; }; 37837E7C1DCFE270000201A0 /* RCTAppleHealthKit+Methods_Sleep.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Sleep.m"; sourceTree = ""; }; + 61232F911E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Methods_Mindfulness.h"; sourceTree = ""; }; + 61232F921E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Mindfulness.m"; sourceTree = ""; }; 64C42D481D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Methods_Vitals.h"; sourceTree = ""; }; 64C42D491D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Vitals.m"; sourceTree = ""; }; 64E0E73D1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Methods_Results.h"; sourceTree = ""; }; @@ -87,6 +90,8 @@ 3774C88F1D2092F20000B3F3 /* RCTAppleHealthKit */ = { isa = PBXGroup; children = ( + 61232F911E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.h */, + 61232F921E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.m */, 64E0E73D1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.h */, 64E0E73E1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.m */, 64C42D481D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.h */, @@ -171,6 +176,7 @@ 3774C8A11D20A6B90000B3F3 /* RCTAppleHealthKit+Utils.m in Sources */, 37837E7D1DCFE270000201A0 /* RCTAppleHealthKit+Methods_Sleep.m in Sources */, 3774C8D41D20C6390000B3F3 /* RCTAppleHealthKit+Methods_Body.m in Sources */, + 61232F931E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.m in Sources */, 64E0E73F1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.m in Sources */, 64C42D4A1D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m in Sources */, 3774C8931D2092F20000B3F3 /* RCTAppleHealthKit.m in Sources */, diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.h new file mode 100644 index 0000000000000000000000000000000000000000..ac2f17cfc80b8d134f07c75260c2130daf18c83a --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.h @@ -0,0 +1,13 @@ +// +// RCTAppleHealthKit+Methods_Mindfulness.h +// RCTAppleHealthKit +// +// + +#import "RCTAppleHealthKit.h" + +@interface RCTAppleHealthKit (Methods_Mindfulness) + +- (void)mindfulness_saveMindfulSession:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +@end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m new file mode 100644 index 0000000000000000000000000000000000000000..b14ef8137a7bc7618f8de087aaf906137d3a0a46 --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m @@ -0,0 +1,42 @@ +// +// RCTAppleHealthKit+Methods_Mindfulness.m +// RCTAppleHealthKit +// +// + + +#import "RCTAppleHealthKit+Methods_Mindfulness.h" +#import "RCTAppleHealthKit+Queries.h" +#import "RCTAppleHealthKit+Utils.h" + +@implementation RCTAppleHealthKit (Methods_Sleep) + + +- (void)mindfulness_saveMindfulSession:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback +{ + double value = [RCTAppleHealthKit doubleFromOptions:input key:@"value" withDefault:(double)0]; + NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil]; + NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; + + if(startDate == nil || endDate == nil){ + callback(@[RCTMakeError(@"startDate and endDate are required in options", nil, nil)]); + return; + } + + HKCategoryType *type = [HKCategoryType categoryTypeForIdentifier: HKCategoryTypeIdentifierMindfulSession]; + HKCategorySample *sample = [HKCategorySample categorySampleWithType:type value:value startDate:startDate endDate:endDate]; + + + [self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) { + if (!success) { + NSLog(@"An error occured saving the mindful session sample %@. The error was: %@.", sample, error); + callback(@[RCTMakeError(@"An error occured saving the mindful session sample", error, nil)]); + return; + } + callback(@[[NSNull null], @(value)]); + }]; + +} + + +@end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m index e050dabc23a4993c94fbc853d0c086e65d809509..b22e6f346770c9153c0223fb5006e186592aff6f 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m @@ -34,7 +34,7 @@ @"ActiveEnergyBurned" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned], @"FlightsClimbed" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed], @"NikeFuel" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierNikeFuel], - @"AppleExerciseTime" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierAppleExerciseTime], +// @"AppleExerciseTime" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierAppleExerciseTime], // Nutrition Identifiers @"DietaryEnergy" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryEnergyConsumed], // Vital Signs Identifiers @@ -47,6 +47,8 @@ @"BloodGlucose" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodGlucose], // Sleep @"SleepAnalysis" : [HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis], + // Mindfulness + @"MindfulSession" : [HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierMindfulSession], }; return readPerms; } @@ -73,6 +75,8 @@ @"DietaryEnergy" : [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryEnergyConsumed], // Sleep @"SleepAnalysis" : [HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis], + // Mindfulness + @"MindfulSession" : [HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierMindfulSession], }; return writePerms; } diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 3a389cea4dcb9afe8448a3a476c45fc8c16b0118..dbe76450fc3eead55c60f3cff62f2fd8e642abb5 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -15,6 +15,7 @@ #import "RCTAppleHealthKit+Methods_Vitals.h" #import "RCTAppleHealthKit+Methods_Results.h" #import "RCTAppleHealthKit+Methods_Sleep.h" +#import "RCTAppleHealthKit+Methods_Mindfulness.h" #import #import @@ -164,6 +165,11 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock [self getModuleInfo:input callback:callback]; } +RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self mindfulness_saveMindfulSession:input callback:callback]; +} + - (void)isHealthKitAvailable:(RCTResponseSenderBlock)callback { diff --git a/README.md b/README.md index 279629387fe3addaebf2212e7e478e6529d26ee5..71233cdd89ad018a9cd7866892fdfd7532b14a87 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ A React Native bridge module for interacting with [Apple Healthkit] data. * [getRespiratoryRateSamples](#getrespiratoryratesamples) * [getBloodGlucoseSamples](#getbloodglucosesamples) * [getSleepSamples](#getsleepsamples) + * [saveMindfulSession](#saveMindfulSession) ## References - Apple Healthkit Documentation [https://developer.apple.com/Healthkit/](https://developer.apple.com/Healthkit/) @@ -129,6 +130,7 @@ The available Healthkit permissions to use with `initHealthkit` | Permission | Healthkit Identifier Type | Read | Write | |------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|------|-------| +<<<<<<< HEAD | ActiveEnergyBurned | [HKQuantityTypeIdentifierActiveEnergyBurned](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifieractiveenergyburned?language=objc) | ✓ | ✓ | | AppleExerciseTime | [HKQuantityTypeIdentifierAppleExerciseTime](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierappleexercisetime?language=objc) | ✓ | | | BasalEnergyBurned | [HKQuantityTypeIdentifierBasalEnergyBurned](https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbasalenergyburned?language=objc) | ✓ | ✓ | @@ -155,6 +157,69 @@ These permissions are exported as constants of the `rn-apple-Healthkit` module. ## Methods +======= +| DateOfBirth | [HKCharacteristicTypeIdentifierDateOfBirth](https://developer.apple.com/reference/healthkit/hkcharacteristictypeidentifierdateofbirth?language=objc) | ✓ | | +| BiologicalSex | [HKCharacteristicTypeIdentifierBiologicalSex](https://developer.apple.com/reference/healthkit/hkcharacteristictypeidentifierbiologicalsex?language=objc) | ✓ | | +| Height | [HKQuantityTypeIdentifierHeight](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierheight?language=objc) | ✓ | ✓ | +| Weight | [HKQuantityTypeIdentifierBodyMass](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbodymass?language=objc) | ✓ | ✓ | +| BodyFatPercentage | [HKQuantityTypeIdentifierBodyFatPercentage](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbodyfatpercentage?language=objc) | ✓ | ✓ | +| BodyMassIndex | [HKQuantityTypeIdentifierBodyMassIndex](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbodymassindex?language=objc) | ✓ | ✓ | +| LeanBodyMass | [HKQuantityTypeIdentifierLeanBodyMass](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierleanbodymass?language=objc) | ✓ | ✓ | +| StepCount | [HKQuantityTypeIdentifierStepCount](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierstepcount?language=objc) | ✓ | ✓ | +| DistanceWalkingRunning | [HKQuantityTypeIdentifierDistanceWalkingRunning](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierdistancewalkingrunning?language=objc) | ✓ | ✓ | +| DistanceCycling | [HKQuantityTypeIdentifierDistanceCycling](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierdistancecycling?language=objc) | ✓ | ✓ | +| BasalEnergyBurned | [HKQuantityTypeIdentifierBasalEnergyBurned](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbasalenergyburned?language=objc) | ✓ | ✓ | +| ActiveEnergyBurned | [HKQuantityTypeIdentifierActiveEnergyBurned](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifieractiveenergyburned?language=objc) | ✓ | ✓ | +| FlightsClimbed | [HKQuantityTypeIdentifierFlightsClimbed](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierflightsclimbed?language=objc) | ✓ | ✓ | +| NikeFuel | [HKQuantityTypeIdentifierNikeFuel](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifiernikefuel?language=objc) | ✓ | | +| AppleExerciseTime | [HKQuantityTypeIdentifierAppleExerciseTime](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierappleexercisetime?language=objc) | ✓ | | +| DietaryEnergy | [HKQuantityTypeIdentifierDietaryEnergyConsumed](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierdietaryenergyconsumed?language=objc) | ✓ | ✓ | +| HeartRate | [HKQuantityTypeIdentifierHeartRate](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierheartrate?language=objc) | ✓ | | +| BodyTemperature | [HKQuantityTypeIdentifierBodyTemperature](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbodytemperature?language=objc) | ✓ | | +| BloodPressureSystolic | [HKQuantityTypeIdentifierBloodPressureSystolic](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodpressuresystolic?language=objc) | ✓ | | +| BloodPressureDiastolic | [HKQuantityTypeIdentifierBloodPressureDiastolic](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodpressurediastolic?language=objc) | ✓ | | +| RespiratoryRate | [HKQuantityTypeIdentifierRespiratoryRate](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierrespiratoryrate?language=objc) | ✓ | | +| BloodGlucose | [HKQuantityTypeIdentifierBloodGlucose](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodglucose?language=objc) | ✓ | +| +| SleepAnalysis | [HKCategoryTypeIdentifierSleepAnalysis](https://developer.apple.com/reference/healthkit/hkcategorytypeidentifiersleepanalysis?language=objc) | ✓ | +| MindfulSession | [HKCategoryTypeIdentifierMindfulSession](https://developer.apple.com/reference/healthkit/hkcategorytypeidentifiermindfulsession?language=objc) | | ✓ | + + + +These permissions are exported as constants of the `react-native-apple-healthkit` module. + +```javascript +import AppleHealthKit from 'react-native-apple-healthkit'; + +... + +// get the available permissions from AppleHealthKit.Constants object +const PERMS = AppleHealthKit.Constants.Permissions; + +// setup healthkit read/write permissions using PERMS +const healthKitOptions = { + permissions: { + read: [ + PERMS.StepCount, + PERMS.Height, + ], + write: [ + PERMS.StepCount + ], + } +}; + +... +``` + + +Options +------- + + +Methods +------- +>>>>>>> 5adade4a95b5b3cd1816a8d203c1e36a702cfa8a #### **`isAvailable`** Check if Healthkit is available on the device. @@ -929,4 +994,26 @@ AppleHealthkit.getSleepSamples(options, (err: Object, results: Array) => }); ``` +#### **`saveMindfulSession`** + +each mindfulness sample represents a period of time with a startDate and an endDate. +the options must contain `startDate` and `endDate` + +```javascript +let options = { + startDate: (new Date(2016,10,1)).toISOString(), // required + endDate: (new Date()).toISOString(), // optional; default now +}; + +``` + +``` +AppleHealthKit.saveMindfulSession(options, (err, res) => { + if (err) return { + return + } + console.log('Mindful session saved') +}); +``` + > *This package is fork from [react-native-apple-Healthkit](https://github.com/GregWilson/react-native-apple-Healthkit)* diff --git a/constants.js b/constants.js index 4b74d04303b8b88c6ac3f8fd904a7c0a767b4f31..16912c55a3559c94d54e44cba681e275c5f068d7 100644 --- a/constants.js +++ b/constants.js @@ -30,6 +30,7 @@ const PERMISSIONS = { RespiratoryRate: 'RespiratoryRate', BloodGlucose: 'BloodGlucose', SleepAnalysis: 'SleepAnalysis', + MindfulSession: 'MindfulSession', }; /**