// // 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