@@ -935,7 +935,7 @@ - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
935
935
// Create the query
936
936
HKStatisticsCollectionQuery *query = [[HKStatisticsCollectionQuery alloc ] initWithQuantityType: quantityType
937
937
quantitySamplePredicate: predicate
938
- options: HKStatisticsOptionCumulativeSum
938
+ options: HKStatisticsOptionCumulativeSum | HKStatisticsOptionSeparateBySource
939
939
anchorDate: anchorDate
940
940
intervalComponents: interval];
941
941
@@ -961,10 +961,33 @@ - (void)fetchCumulativeSumStatisticsCollection:(HKQuantityType *)quantityType
961
961
NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate: startDate];
962
962
NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate: endDate];
963
963
964
+ NSMutableArray *metadata = [NSMutableArray arrayWithCapacity: 1 ];
965
+
966
+ for (HKSource *source in result.sources ) {
967
+
968
+ NSString *bundleIdentifier = source.bundleIdentifier ;
969
+ NSString *name = source.name ;
970
+ HKQuantity *sourceQuantity = [result sumQuantityForSource: source];
971
+ double quantity = [sourceQuantity doubleValueForUnit: unit];
972
+
973
+
974
+ if (quantity != 0 ) {
975
+ NSDictionary *sourceItem = @{
976
+ @" sourceId" : bundleIdentifier,
977
+ @" sourceName" : name,
978
+ @" quantity" : @(quantity),
979
+ };
980
+
981
+ [metadata addObject: sourceItem];
982
+ }
983
+ }
984
+
985
+
964
986
NSDictionary *elem = @{
965
987
@" value" : @(value),
966
988
@" startDate" : startDateString,
967
989
@" endDate" : endDateString,
990
+ @" metadata" : metadata,
968
991
};
969
992
[data addObject: elem];
970
993
}
@@ -1214,3 +1237,4 @@ - (void)fetchActivitySummary:(NSDate *)startDate
1214
1237
}
1215
1238
1216
1239
@end
1240
+
0 commit comments