Commit 55f64400 authored by skleest's avatar skleest

Save mindfulness session

parent 906ba45b
//
// RCTAppleHealthKit+Methods_Mindfulness.h
// RCTAppleHealthKit
//
//
#import "RCTAppleHealthKit.h"
@interface RCTAppleHealthKit (Methods_Mindfulness)
- (void)mindfulness_saveMindfulSession:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end
//
// 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
{
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;
}
// original
HKQuantity *quantity = [HKQuantity quantityWithUnit:unit doubleValue:value];
HKQuantityType *type = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKQuantitySample *sample = [HKQuantitySample categorySampleWithType:type quantity:quantity startDate:startDate endDate:endDate];
// new
HKCategoryType *type = [HKCategoryType categoryTypeForIdentifier: HKCategoryTypeIdentifierMindfulSession];
HKCategorySample *sample = [HKCategorySample categorySampleWithType:type value:nil 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 step count sample", error, nil)]);
return;
}
callback(@[[NSNull null], @(value)]);
}];
}
@end
......@@ -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;
}
......
......@@ -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 "RCTBridge.h"
#import "RCTEventDispatcher.h"
......@@ -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
{
......
......@@ -26,6 +26,7 @@ const PERMISSIONS = {
RespiratoryRate: 'RespiratoryRate',
BloodGlucose: 'BloodGlucose',
SleepAnalysis: 'SleepAnalysis',
MindfulSession: 'MindfulSession',
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment