From b27e93cb5afbb9852d432add02b5ea5740839346 Mon Sep 17 00:00:00 2001 From: Patryk Fryda Date: Thu, 15 Feb 2024 21:06:10 +0100 Subject: [PATCH] Fix saveMindfulSession --- .../RCTAppleHealthKit+Methods_Mindfulness.m | 5 ++--- docs/saveMindfulSession.md | 4 ++-- index.d.ts | 9 +++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m index da9ec78b..f3fd6504 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m @@ -60,7 +60,6 @@ - (void)mindfulness_getMindfulSession:(NSDictionary *)input callback:(RCTRespons - (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]]; @@ -70,7 +69,7 @@ - (void)mindfulness_saveMindfulSession:(NSDictionary *)input callback:(RCTRespon } HKCategoryType *type = [HKCategoryType categoryTypeForIdentifier: HKCategoryTypeIdentifierMindfulSession]; - HKCategorySample *sample = [HKCategorySample categorySampleWithType:type value:value startDate:startDate endDate:endDate]; + HKCategorySample *sample = [HKCategorySample categorySampleWithType:type value:HKCategoryValueNotApplicable startDate:startDate endDate:endDate]; [self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) { @@ -78,7 +77,7 @@ - (void)mindfulness_saveMindfulSession:(NSDictionary *)input callback:(RCTRespon callback(@[RCTJSErrorFromNSError(error)]); return; } - callback(@[[NSNull null], @(value)]); + callback(@[[NSNull null], @(success)]); }]; } diff --git a/docs/saveMindfulSession.md b/docs/saveMindfulSession.md index 3b4cf456..70800f4c 100644 --- a/docs/saveMindfulSession.md +++ b/docs/saveMindfulSession.md @@ -16,13 +16,13 @@ Call the method: ```javascript AppleHealthKit.saveMindfulSession( - (options: HealthInputOptions), + (options: HealthCategoryValueOptions), (err: Object, results: number) => { if (err) return { return, } - // mindfullSession successfully saved + // mindfulSession successfully saved }, ) ``` diff --git a/index.d.ts b/index.d.ts index 0cf0e280..11f3809c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -361,7 +361,7 @@ declare module 'react-native-health' { ): void saveMindfulSession( - options: HealthValueOptions, + options: HealthCategoryValueOptions, callback: (error: string, result: HealthValue) => void, ): void @@ -590,10 +590,15 @@ declare module 'react-native-health' { } export interface HealthActivityOptions - extends Omit, 'value'> { + extends Omit { type: HealthActivity } + export interface HealthCategoryValueOptions { + startDate: string; + endDate?: string; + } + export interface HealthObserverOptions { type: HealthObserver }