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
76fa1a2d
Commit
76fa1a2d
authored
Nov 06, 2016
by
Greg Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added sleep category query to queries
parent
ea7b0437
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+6
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+96
-0
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
76fa1a2d
...
...
@@ -38,4 +38,10 @@
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
-
(
void
)
fetchSleepCategorySamplesForPredicate
:(
NSPredicate
*
)
predicate
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
@end
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
76fa1a2d
...
...
@@ -106,6 +106,102 @@
}
-
(
void
)
fetchSleepCategorySamplesForPredicate
:(
NSPredicate
*
)
predicate
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
{
NSSortDescriptor
*
timeSortDescriptor
=
[[
NSSortDescriptor
alloc
]
initWithKey
:
HKSampleSortIdentifierEndDate
ascending:
false
];
// declare the block
void
(
^
handlerBlock
)(
HKSampleQuery
*
query
,
NSArray
*
results
,
NSError
*
error
);
// create and assign the block
handlerBlock
=
^
(
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
(
HKCategorySample
*
sample
in
results
)
{
HKCategoryType
*
catType
=
sample
.
categoryType
;
NSInteger
*
val
=
sample
.
value
;
// HKQuantity *quantity = sample.quantity;
// double value = [quantity doubleValueForUnit:unit];
NSString
*
startDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
startDate
];
NSString
*
endDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
endDate
];
NSDictionary
*
elem
=
@{
@"value"
:
@
((
(
float
)
*
val
)),
@"catType"
:
catType
.
identifier
,
@"startDate"
:
startDateString
,
@"endDate"
:
endDateString
,
};
[
data
addObject
:
elem
];
}
completion
(
data
,
error
);
});
}
};
// HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:quantityType
// predicate:predicate
// limit:lim
// sortDescriptors:@[timeSortDescriptor]
// resultsHandler:handlerBlock];
HKCategoryType
*
categoryType
=
[
HKObjectType
categoryTypeForIdentifier
:
HKCategoryTypeIdentifierSleepAnalysis
];
// HKCategorySample *categorySample =
// [HKCategorySample categorySampleWithType:categoryType
// value:value
// startDate:startDate
// endDate:endDate];
HKSampleQuery
*
query
=
[[
HKSampleQuery
alloc
]
initWithSampleType
:
categoryType
predicate:
predicate
limit:
lim
sortDescriptors:
@[
timeSortDescriptor
]
resultsHandler:
handlerBlock
];
[
self
.
healthStore
executeQuery
:
query
];
}
-
(
void
)
fetchCorrelationSamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
...
...
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