Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix saveMindfulSession #362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Mindfulness.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];

Expand All @@ -70,15 +69,15 @@ - (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) {
if (!success) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
callback(@[[NSNull null], @(value)]);
callback(@[[NSNull null], @(success)]);
}];

}
Expand Down
4 changes: 2 additions & 2 deletions docs/saveMindfulSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
```
Expand Down
9 changes: 7 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ declare module 'react-native-health' {
): void

saveMindfulSession(
options: HealthValueOptions,
options: HealthCategoryValueOptions,
callback: (error: string, result: HealthValue) => void,
): void

Expand Down Expand Up @@ -590,10 +590,15 @@ declare module 'react-native-health' {
}

export interface HealthActivityOptions
extends Omit<Omit<HealthValueOptions, 'unit'>, 'value'> {
extends Omit<HealthValueOptions, 'unit' | 'value'> {
type: HealthActivity
}

export interface HealthCategoryValueOptions {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know if I should create a separate type of this and how to name. There is no value in saveMindfulSession

startDate: string;
endDate?: string;
}

export interface HealthObserverOptions {
type: HealthObserver
}
Expand Down