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
c3b53243
Commit
c3b53243
authored
Feb 04, 2018
by
Evgenii Evstropov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update work around isTracked flag, to perfom only one quert for tracked and non-tracked samples
parent
dd643582
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
49 deletions
+37
-49
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
+3
-23
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+1
-3
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+33
-23
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
View file @
c3b53243
...
...
@@ -53,27 +53,11 @@
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
key
:
@"unit"
withDefault
:
[
HKUnit
countUnit
]];
NSUInteger
limit
=
[
RCTAppleHealthKit
uintFromOptions
:
input
key
:
@"limit"
withDefault
:
HKObjectQueryNoLimit
];
BOOL
ascending
=
[
RCTAppleHealthKit
boolFromOptions
:
input
key
:
@"ascending"
withDefault
:
false
];
BOOL
isTracked
=
[
RCTAppleHealthKit
boolFromOptions
:
input
key
:
@"isTracked"
withDefault
:
true
];
NSString
*
type
=
[
RCTAppleHealthKit
stringFromOptions
:
input
key
:
@"type"
withDefault
:
@"Walking"
];
NSDate
*
startDate
=
[
RCTAppleHealthKit
dateFromOptions
:
input
key
:
@"startDate"
withDefault
:
nil
];
NSDate
*
startDate
=
[
RCTAppleHealthKit
dateFromOptions
:
input
key
:
@"startDate"
withDefault
:
[
NSDate
date
]
];
NSDate
*
endDate
=
[
RCTAppleHealthKit
dateFromOptions
:
input
key
:
@"endDate"
withDefault
:
[
NSDate
date
]];
if
(
startDate
==
nil
){
callback
(@[
RCTMakeError
(
@"startDate is required in options"
,
nil
,
nil
)]);
return
;
}
NSDateFormatter
*
formatter
=
[[
NSDateFormatter
alloc
]
init
];
[
formatter
setDateFormat
:
@"YYYY-MM-dd-hh-mm-ss"
];
// no isTracked
NSArray
*
subPredicates
=
[[
NSArray
alloc
]
init
];
NSMutableArray
*
subPredicatesAux
=
[[
NSMutableArray
alloc
]
init
];
NSPredicate
*
predicateDate
=
[
HKQuery
predicateForSamplesWithStartDate
:
startDate
endDate
:
endDate
options
:
HKQueryOptionStrictStartDate
];
NSPredicate
*
predicateType
=
isTracked
?
[
NSPredicate
predicateWithFormat
:
@"metadata.%K != YES"
,
HKMetadataKeyWasUserEntered
]
:
[
NSPredicate
predicateWithFormat
:
@"metadata.%K == YES"
,
HKMetadataKeyWasUserEntered
];
[
subPredicatesAux
addObject
:
predicateDate
];
[
subPredicatesAux
addObject
:
predicateType
];
subPredicates
=
[
subPredicatesAux
copy
];
NSPredicate
*
predicate
=
[
NSCompoundPredicate
andPredicateWithSubpredicates
:[
NSArray
arrayWithObjects
:
predicateType
,
predicateDate
,
nil
]
];
NSPredicate
*
predicate
=
[
HKQuery
predicateForSamplesWithStartDate
:
startDate
endDate
:
endDate
options
:
HKQueryOptionStrictStartDate
];
HKSampleType
*
samplesType
=
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierStepCount
];
if
([
type
isEqual
:
@"Walking"
])
{
...
...
@@ -90,15 +74,11 @@
samplesType
=
[
HKObjectType
workoutType
];
}
NSString
*
paramName
=
@"isTracked"
;
[
self
fetchQuantitySamplesOfType
:
samplesType
[
self
fetchSamplesOfType
:
samplesType
unit:
unit
predicate:
predicate
ascending:
ascending
limit:
limit
additionalParamName:
paramName
additionalParam:
isTracked
completion:
^
(
NSArray
*
results
,
NSError
*
error
)
{
if
(
results
){
callback
(@[[
NSNull
null
],
results
]);
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
c3b53243
...
...
@@ -18,7 +18,7 @@
startDate
:(
NSDate
*
)
startDate
endDate
:(
NSDate
*
)
endDate
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
-
(
void
)
fetch
QuantitySamplesOfType
:(
HKQuantity
Type
*
)
quantityType
-
(
void
)
fetch
SamplesOfType
:(
HKSample
Type
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
...
...
@@ -29,8 +29,6 @@
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
additionalParamName
:(
NSString
*
)
paramName
additionalParam
:(
BOOL
)
param
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
-
(
void
)
fetchCorrelationSamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
c3b53243
...
...
@@ -48,7 +48,6 @@
[
self
.
healthStore
executeQuery
:
query
];
}
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
...
...
@@ -105,13 +104,13 @@
[
self
.
healthStore
executeQuery
:
query
];
}
-
(
void
)
fetchQuantitySamplesOfType
:(
HKSampleType
*
)
type
-
(
void
)
fetchSamplesOfType
:(
HKSampleType
*
)
type
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
additionalParamName
:(
NSString
*
)
paramName
additionalParam
:(
BOOL
)
param
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
{
NSSortDescriptor
*
timeSortDescriptor
=
[[
NSSortDescriptor
alloc
]
initWithKey
:
HKSampleSortIdentifierEndDate
ascending:
asc
];
...
...
@@ -139,14 +138,19 @@
NSString
*
startDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
startDate
];
NSString
*
endDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
endDate
];
bool
isTracked
=
true
;
for
(
id
key
in
[
sample
metadata
])
if
(
key
==
HKMetadataKeyWasUserEntered
)
{
isTracked
=
false
;
}
NSDictionary
*
elem
=
@{
@"type"
:
type
,
@"energy"
:
@
(
energy
),
@"isTracked"
:
@
(
isTracked
),
@"distance"
:
@
(
distance
),
@"startDate"
:
startDateString
,
@"endDate"
:
endDateString
,
paramName
:
@
(
param
),
@"endDate"
:
endDateString
};
[
data
addObject
:
elem
];
...
...
@@ -159,11 +163,17 @@
NSString
*
startDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
startDate
];
NSString
*
endDateString
=
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
sample
.
endDate
];
bool
isTracked
=
true
;
for
(
id
key
in
[
sample
metadata
])
if
(
key
==
HKMetadataKeyWasUserEntered
)
{
isTracked
=
false
;
}
NSDictionary
*
elem
=
@{
@"value"
:
@
(
value
),
@"isTracked"
:
@
(
isTracked
),
@"startDate"
:
startDateString
,
@"endDate"
:
endDateString
,
paramName
:
@
(
param
),
@"endDate"
:
endDateString
};
[
data
addObject
:
elem
];
...
...
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