Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rn-apple-healthkit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ym
rn-apple-healthkit
Commits
295e4b0a
Commit
295e4b0a
authored
Jun 29, 2016
by
Greg Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new query fetchQuantitySamplesOfType to Queries
parent
1a1c4c71
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
33 deletions
+73
-33
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+10
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+63
-33
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
295e4b0a
...
@@ -19,4 +19,14 @@
...
@@ -19,4 +19,14 @@
startDate
:(
NSDate
*
)
startDate
startDate
:(
NSDate
*
)
startDate
endDate
:(
NSDate
*
)
endDate
endDate
:(
NSDate
*
)
endDate
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
@end
@end
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
295e4b0a
...
@@ -12,8 +12,11 @@
...
@@ -12,8 +12,11 @@
@implementation
RCTAppleHealthKit
(
Queries
)
@implementation
RCTAppleHealthKit
(
Queries
)
-
(
void
)
fetchMostRecentQuantitySampleOfType
:(
HKQuantityType
*
)
quantityType
predicate
:(
NSPredicate
*
)
predicate
completion
:(
void
(
^
)(
HKQuantity
*
,
NSDate
*
,
NSDate
*
,
NSError
*
))
completion
{
NSSortDescriptor
*
timeSortDescriptor
=
[[
NSSortDescriptor
alloc
]
initWithKey
:
HKSampleSortIdentifierEndDate
ascending
:
NO
];
-
(
void
)
fetchMostRecentQuantitySampleOfType
:(
HKQuantityType
*
)
quantityType
predicate
:(
NSPredicate
*
)
predicate
completion
:(
void
(
^
)(
HKQuantity
*
,
NSDate
*
,
NSDate
*
,
NSError
*
))
completion
{
NSSortDescriptor
*
timeSortDescriptor
=
[[
NSSortDescriptor
alloc
]
initWithKey
:
HKSampleSortIdentifierEndDate
ascending
:
NO
];
HKSampleQuery
*
query
=
[[
HKSampleQuery
alloc
]
initWithSampleType
:
quantityType
HKSampleQuery
*
query
=
[[
HKSampleQuery
alloc
]
initWithSampleType
:
quantityType
predicate:
predicate
predicate:
predicate
limit:
1
limit:
1
...
@@ -41,6 +44,63 @@
...
@@ -41,6 +44,63 @@
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
{
NSSortDescriptor
*
timeSortDescriptor
=
[[
NSSortDescriptor
alloc
]
initWithKey
:
HKSampleSortIdentifierEndDate
ascending
:
asc
];
HKSampleQuery
*
query
=
[[
HKSampleQuery
alloc
]
initWithSampleType
:
quantityType
predicate:
predicate
limit:
lim
sortDescriptors:
@[
timeSortDescriptor
]
resultsHandler:
^
(
HKSampleQuery
*
query
,
NSArray
*
results
,
NSError
*
error
)
{
if
(
!
results
)
{
if
(
completion
)
{
completion
(
nil
,
error
);
}
return
;
}
if
(
completion
)
{
NSMutableArray
*
data
=
[
NSMutableArray
arrayWithCapacity
:
1
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
for
(
HKQuantitySample
*
sample
in
results
)
{
HKQuantity
*
quantity
=
sample
.
quantity
;
// NSDate *startDate = sample.startDate;
// NSDate *endDate = sample.endDate;
double
value
=
[
quantity
doubleValueForUnit
:
unit
];
NSString
*
startDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
startDate
];
NSString
*
endDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
endDate
];
NSDictionary
*
elem
=
@{
@"value"
:
@
(
value
),
@"startDate"
:
startDateString
,
@"endDate"
:
endDateString
,
};
[
data
addObject
:
elem
];
}
completion
(
data
,
error
);
});
}
}];
[
self
.
healthStore
executeQuery
:
query
];
}
...
@@ -83,27 +143,6 @@
...
@@ -83,27 +143,6 @@
//- (void)fetchSumOfSamplesBetweenDatesForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit startDate:(NSDate *)startDate endDate:(NSDate *)endDate completion:(void (^)(NSArray *, NSError *))completionHandler {
// NSPredicate *predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
//
// HKStatisticsQuery *query = [[HKStatisticsQuery alloc] initWithQuantityType:quantityType
// quantitySamplePredicate:predicate
// options:HKStatisticsOptionCumulativeSum
// completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {
// HKQuantity *sum = [result sumQuantity];
// if (completionHandler) {
// double value = [sum doubleValueForUnit:unit];
// completionHandler(value, error);
// }
// }];
//
// [self.healthStore executeQuery:query];
//}
-
(
void
)
fetchCumulativeSumStatisticsCollection
:(
HKQuantityType
*
)
quantityType
-
(
void
)
fetchCumulativeSumStatisticsCollection
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
unit
:(
HKUnit
*
)
unit
startDate
:(
NSDate
*
)
startDate
startDate
:(
NSDate
*
)
startDate
...
@@ -119,30 +158,21 @@
...
@@ -119,30 +158,21 @@
fromDate:
[
NSDate
date
]];
fromDate:
[
NSDate
date
]];
anchorComponents
.
hour
=
0
;
anchorComponents
.
hour
=
0
;
NSDate
*
anchorDate
=
[
calendar
dateFromComponents
:
anchorComponents
];
NSDate
*
anchorDate
=
[
calendar
dateFromComponents
:
anchorComponents
];
// HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
// Create the query
// Create the query
HKStatisticsCollectionQuery
*
query
=
[[
HKStatisticsCollectionQuery
alloc
]
initWithQuantityType
:
quantityType
HKStatisticsCollectionQuery
*
query
=
[[
HKStatisticsCollectionQuery
alloc
]
initWithQuantityType
:
quantityType
quantitySamplePredicate:
nil
quantitySamplePredicate:
nil
options:
HKStatisticsOptionCumulativeSum
options:
HKStatisticsOptionCumulativeSum
anchorDate:
anchorDate
anchorDate:
anchorDate
intervalComponents:
interval
];
intervalComponents:
interval
];
// Set the results handler
// Set the results handler
query
.
initialResultsHandler
=
^
(
HKStatisticsCollectionQuery
*
query
,
HKStatisticsCollection
*
results
,
NSError
*
error
)
{
query
.
initialResultsHandler
=
^
(
HKStatisticsCollectionQuery
*
query
,
HKStatisticsCollection
*
results
,
NSError
*
error
)
{
if
(
error
)
{
if
(
error
)
{
// Perform proper error handling here
// Perform proper error handling here
NSLog
(
@"*** An error occurred while calculating the statistics: %@ ***"
,
error
.
localizedDescription
);
NSLog
(
@"*** An error occurred while calculating the statistics: %@ ***"
,
error
.
localizedDescription
);
}
}
// NSDate *endDate = [NSDate date];
// NSDate *startDate = [calendar dateByAddingUnit:NSCalendarUnitDay
// value:-7
// toDate:endDate
// options:0];
// Plot the daily step counts over the past 7 days
NSMutableArray
*
data
=
[
NSMutableArray
arrayWithCapacity
:
1
];
NSMutableArray
*
data
=
[
NSMutableArray
arrayWithCapacity
:
1
];
[
results
enumerateStatisticsFromDate
:
startDate
[
results
enumerateStatisticsFromDate
:
startDate
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment