Skip to content

Commit 7ce15ab

Browse files
authored
Merge branch 'master' into master
2 parents 504a3c9 + b1aaf5f commit 7ce15ab

File tree

82 files changed

+4716
-2744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4716
-2744
lines changed

.github/auto_assign.yml

-18
This file was deleted.

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- (void)body_saveWeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1616

1717
- (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
18+
- (void)body_getBodyMassIndexSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1819
- (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1920

2021
- (void)body_getLatestHeight:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@@ -25,6 +26,10 @@
2526
- (void)body_getWaistCircumferenceSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
2627
- (void)body_saveWaistCircumference:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
2728

29+
- (void)body_getLatestPeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
30+
- (void)body_getPeakFlowSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
31+
- (void)body_savePeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
32+
2833
- (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
2934
- (void)body_getBodyFatPercentageSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
3035
- (void)body_saveBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m

+106
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,37 @@ - (void)body_getLatestBodyMassIndex:(NSDictionary *)input callback:(RCTResponseS
118118
}];
119119
}
120120

121+
- (void)body_getBodyMassIndexSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
122+
{
123+
HKQuantityType *bmiType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex];
124+
125+
HKUnit *countUnit = [HKUnit countUnit];
126+
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
127+
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
128+
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
129+
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
130+
if(startDate == nil){
131+
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
132+
return;
133+
}
134+
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
135+
136+
[self fetchQuantitySamplesOfType:bmiType
137+
unit:countUnit
138+
predicate:predicate
139+
ascending:ascending
140+
limit:limit
141+
completion:^(NSArray *results, NSError *error) {
142+
if(results){
143+
callback(@[[NSNull null], results]);
144+
return;
145+
} else {
146+
callback(@[RCTJSErrorFromNSError(error)]);
147+
return;
148+
}
149+
}];
150+
}
151+
121152

122153
- (void)body_saveBodyMassIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
123154
{
@@ -297,6 +328,81 @@ - (void)body_saveWaistCircumference:(NSDictionary *)input callback:(RCTResponseS
297328
}];
298329
}
299330

331+
- (void)body_getLatestPeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
332+
{
333+
HKQuantityType *peakFlowType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeakExpiratoryFlowRate];
334+
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[[HKUnit literUnit] unitDividedByUnit:[HKUnit minuteUnit]]];
335+
336+
[self fetchMostRecentQuantitySampleOfType:peakFlowType
337+
predicate:nil
338+
completion:^(HKQuantity *mostRecentQuantity, NSDate *startDate, NSDate *endDate, NSError *error) {
339+
if (error) {
340+
NSLog(@"error getting latest peak flow: %@", error);
341+
callback(@[RCTMakeError(@"error getting latest peak flow", error, nil)]);
342+
}
343+
else {
344+
// Determine the peak flow rate in the required unit.
345+
double peakFlow = [mostRecentQuantity doubleValueForUnit:unit];
346+
347+
NSDictionary *response = @{
348+
@"value" : @(peakFlow),
349+
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
350+
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
351+
};
352+
353+
callback(@[[NSNull null], response]);
354+
}
355+
}];
356+
}
357+
358+
- (void)body_getPeakFlowSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
359+
{
360+
HKQuantityType *peakFlowType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeakExpiratoryFlowRate];
361+
362+
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[[HKUnit literUnit] unitDividedByUnit:[HKUnit minuteUnit]]];
363+
364+
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
365+
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
366+
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
367+
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
368+
if(startDate == nil){
369+
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
370+
return;
371+
}
372+
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
373+
374+
[self fetchQuantitySamplesOfType:peakFlowType
375+
unit:unit
376+
predicate:predicate
377+
ascending:ascending
378+
limit:limit
379+
completion:^(NSArray *results, NSError *error) {
380+
if(results){
381+
callback(@[[NSNull null], results]);
382+
} else {
383+
callback(@[RCTJSErrorFromNSError(error)]);
384+
}
385+
}];
386+
}
387+
388+
- (void)body_savePeakFlow:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
389+
{
390+
double peakFlow = [RCTAppleHealthKit doubleValueFromOptions:input];
391+
NSDate *sampleDate = [RCTAppleHealthKit dateFromOptionsDefaultNow:input];
392+
HKUnit *peakFlowUnit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[[HKUnit literUnit] unitDividedByUnit:[HKUnit minuteUnit]]];
393+
394+
HKQuantity *peakFlowQuantity = [HKQuantity quantityWithUnit:peakFlowUnit doubleValue:peakFlow];
395+
HKQuantityType *peakFlowType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeakExpiratoryFlowRate];
396+
HKQuantitySample *peakFlowSample = [HKQuantitySample quantitySampleWithType:peakFlowType quantity:peakFlowQuantity startDate:sampleDate endDate:sampleDate];
397+
398+
[self.healthStore saveObject:peakFlowSample withCompletion:^(BOOL success, NSError *error) {
399+
if (!success) {
400+
callback(@[RCTJSErrorFromNSError(error)]);
401+
return;
402+
}
403+
callback(@[[NSNull null], @(peakFlow)]);
404+
}];
405+
}
300406

301407
- (void)body_getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
302408
{

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Dietary.h

+2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
- (void)saveWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1616
- (void)getWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
17+
- (void)getWaterSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1718

1819
- (void)dietary_getEnergyConsumedSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1920
- (void)dietary_getProteinSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
21+
- (void)dietary_getFiberSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
2022
- (void)dietary_getTotalFatSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
2123
@end

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Dietary.m

+66
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,37 @@ - (void)dietary_getProteinSamples:(NSDictionary *)input callback:(RCTResponseSen
108108
}];
109109
}
110110

111+
- (void)dietary_getFiberSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
112+
{
113+
HKQuantityType *fiberType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryFiber];
114+
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit gramUnit]];
115+
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
116+
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
117+
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
118+
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
119+
if(startDate == nil){
120+
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
121+
return;
122+
}
123+
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
124+
125+
[self fetchQuantitySamplesOfType:fiberType
126+
unit:unit
127+
predicate:predicate
128+
ascending:ascending
129+
limit:limit
130+
completion:^(NSArray *results, NSError *error) {
131+
if(results){
132+
callback(@[[NSNull null], results]);
133+
return;
134+
} else {
135+
NSLog(@"An error occured while retrieving the fiber sample %@. The error was: ", error);
136+
callback(@[RCTMakeError(@"An error occured while retrieving the fiber sample", error, nil)]);
137+
return;
138+
}
139+
}];
140+
}
141+
111142
- (void)saveFood:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
112143
{
113144
NSString *foodNameValue = [RCTAppleHealthKit stringFromOptions:input key:@"foodName" withDefault:nil];
@@ -533,4 +564,39 @@ - (void)getWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
533564
}];
534565
}
535566

567+
- (void)getWaterSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
568+
{
569+
HKQuantityType *dietaryWaterType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryWater];
570+
HKUnit *literUnit = [HKUnit literUnit];
571+
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
572+
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
573+
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
574+
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
575+
BOOL includeManuallyAdded = [RCTAppleHealthKit boolFromOptions:input key:@"includeManuallyAdded" withDefault:true];
576+
577+
578+
if(startDate == nil) {
579+
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
580+
return;
581+
}
582+
583+
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
584+
585+
[self fetchQuantitySamplesOfType:dietaryWaterType
586+
unit:literUnit
587+
predicate:predicate
588+
ascending:ascending
589+
limit:limit
590+
completion:^(NSArray *results, NSError *error) {
591+
if(results){
592+
callback(@[[NSNull null], results]);
593+
return;
594+
} else {
595+
NSLog(@"An error occured while retrieving the water sample %@. The error was: ", error);
596+
callback(@[RCTMakeError(@"An error occured while retrieving the water sample", error, nil)]);
597+
return;
598+
}
599+
}];
600+
}
601+
536602
@end

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- (void)fitness_getSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1515
- (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1616
- (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
17+
- (void)fitness_saveWalkingRunningDistance:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1718
- (void)fitness_initializeStepEventObserver:(NSDictionary *)input hasListeners:(bool)hasListeners callback:(RCTResponseSenderBlock)callback;
1819
- (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1920
- (void)fitness_getDailyDistanceWalkingRunningSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m

+31-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ - (void)fitness_getStepCountOnDay:(NSDictionary *)input callback:(RCTResponseSen
3535
includeManuallyAdded:includeManuallyAdded
3636
day:date
3737
completion:^(double value, NSDate *startDate, NSDate *endDate, NSError *error) {
38-
if (!value && value != 0) {
38+
if ((!value && value != 0) || error != nil) {
3939
callback(@[RCTJSErrorFromNSError(error)]);
4040
return;
4141
}
@@ -152,6 +152,32 @@ - (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock
152152
}];
153153
}
154154

155+
- (void)fitness_saveWalkingRunningDistance:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
156+
{
157+
double distance = [RCTAppleHealthKit doubleValueFromOptions:input];
158+
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
159+
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
160+
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]];
161+
162+
if(startDate == nil || endDate == nil){
163+
callback(@[RCTMakeError(@"startDate and endDate are required in options", nil, nil)]);
164+
return;
165+
}
166+
167+
HKQuantity *quantity = [HKQuantity quantityWithUnit:unit doubleValue:distance];
168+
HKQuantityType *type = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
169+
HKQuantitySample *sample = [HKQuantitySample quantitySampleWithType:type quantity:quantity startDate:startDate endDate:endDate];
170+
171+
[self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) {
172+
if (!success) {
173+
callback(@[RCTJSErrorFromNSError(error)]);
174+
return;
175+
}
176+
callback(@[[NSNull null], @(distance)]);
177+
}];
178+
}
179+
180+
155181

156182
- (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
157183
{
@@ -192,7 +218,7 @@ - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(R
192218
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
193219

194220
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
195-
if (!distance && distance != 0) {
221+
if ((!distance && distance != 0) || error != nil) {
196222
callback(@[RCTJSErrorFromNSError(error)]);
197223
return;
198224
}
@@ -251,7 +277,7 @@ - (void)fitness_getDistanceSwimmingOnDay:(NSDictionary *)input callback:(RCTResp
251277
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceSwimming];
252278

253279
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
254-
if (!distance && distance != 0) {
280+
if ((!distance && distance != 0) || error != nil) {
255281
callback(@[RCTJSErrorFromNSError(error)]);
256282
return;
257283
}
@@ -308,7 +334,7 @@ - (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTRespo
308334
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];
309335

310336
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double distance, NSDate *startDate, NSDate *endDate, NSError *error) {
311-
if (!distance && distance != 0) {
337+
if ((!distance && distance != 0) || error != nil) {
312338
callback(@[RCTJSErrorFromNSError(error)]);
313339
return;
314340
}
@@ -365,7 +391,7 @@ - (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTRespon
365391
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];
366392

367393
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit includeManuallyAdded:includeManuallyAdded day:date completion:^(double count, NSDate *startDate, NSDate *endDate, NSError *error) {
368-
if (!count && count != 0) {
394+
if ((!count && count != 0) || error != nil) {
369395
callback(@[RCTJSErrorFromNSError(error)]);
370396
return;
371397
}

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111

1212
- (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1313
- (void)results_getCarbohydratesSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
14+
- (void)results_getInsulinDeliverySamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1415
- (void)results_saveBloodGlucoseSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1516
- (void)results_saveCarbohydratesSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
16-
17+
- (void)results_deleteBloodGlucoseSample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;
18+
- (void)results_deleteCarbohydratesSample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;
19+
- (void)results_saveInsulinDeliverySample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
20+
- (void)results_deleteInsulinDeliverySample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;
21+
- (void)results_registerObservers:(RCTBridge *)bridge hasListeners:(bool)hasListeners;
1722

1823
@end

0 commit comments

Comments
 (0)