-
Notifications
You must be signed in to change notification settings - Fork 237
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
Add headphone/environmental audio exposure data methods #128
Add headphone/environmental audio exposure data methods #128
Conversation
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit]; | ||
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false]; | ||
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil]; | ||
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; | ||
if(startDate == nil){ | ||
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]); | ||
return; | ||
} | ||
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate]; | ||
|
||
[self fetchQuantitySamplesOfType:environmentalAudioExposureType | ||
unit:unit | ||
predicate:predicate | ||
ascending:ascending | ||
limit:limit | ||
completion:^(NSArray *results, NSError *error) { | ||
if(results){ | ||
callback(@[[NSNull null], results]); | ||
return; | ||
} else { | ||
callback(@[RCTJSErrorFromNSError(error)]); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole chunk of code is duplicated many times in this library (including in this file). A near future enhancement could be to add a utility function to parse the inputs and fetch the samples for a given type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, we should get a better approach with the migration to Swift! Glad if you can help us with that.
Can you fix these conflicts? @klandell |
Description
Adds support for
HKQuantityTypeIdentifierHeadphoneAudioExposure
andHKQuantityTypeIdentifierEnvironmentalAudioExposure
.Fixes #127
Type of change
Please delete options that are not relevant.
Checklist: