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
fbeb3980
Commit
fbeb3980
authored
Sep 04, 2019
by
冷佳娟
💪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HRB-3175
修改體重取得資料為 Double 值
parent
815a58f7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
1 deletion
+85
-1
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
+1
-1
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+6
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+78
-0
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
View file @
fbeb3980
...
...
@@ -60,7 +60,7 @@
}
NSPredicate
*
predicate
=
[
RCTAppleHealthKit
predicateForSamplesBetweenDates
:
startDate
endDate
:
endDate
];
[
self
fetchQuantitySamplesOfType
:
weightType
[
self
fetchQuantity
Double
SamplesOfType
:
weightType
unit:
unit
predicate:
predicate
ascending:
ascending
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
fbeb3980
...
...
@@ -24,6 +24,12 @@
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
-
(
void
)
fetchQuantityDoubleSamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
-
(
void
)
fetchCorrelationSamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
fbeb3980
...
...
@@ -129,6 +129,84 @@
}
-
(
void
)
fetchQuantityDoubleSamplesOfType
:(
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
];
// 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
(
HKQuantitySample
*
sample
in
results
)
{
HKQuantity
*
quantity
=
sample
.
quantity
;
double
value
=
[
quantity
doubleValueForUnit
:
unit
];
int
startDateTimestamp
=
[
RCTAppleHealthKit
buildTimestampFromDate
:
sample
.
startDate
];
int
endDateTimestamp
=
[
RCTAppleHealthKit
buildTimestampFromDate
:
sample
.
endDate
];
NSString
*
deviceName
=
sample
.
device
.
name
?
sample
.
device
.
name
:
@""
;
NSString
*
deviceManufacturer
=
sample
.
device
.
manufacturer
?
sample
.
device
.
manufacturer
:
@""
;
NSString
*
deviceHardwareVer
=
sample
.
device
.
hardwareVersion
?
sample
.
device
.
hardwareVersion
:
@""
;
NSString
*
deviceSoftwareVer
=
sample
.
device
.
softwareVersion
?
sample
.
device
.
softwareVersion
:
@""
;
NSString
*
sourceName
=
sample
.
sourceRevision
.
source
.
name
;
NSString
*
sourceId
=
sample
.
sourceRevision
.
source
.
bundleIdentifier
;
NSString
*
uuid
=
sample
.
UUID
.
UUIDString
;
NSString
*
metadata
=
[
sample
.
metadata
==
nil
?
@""
:
sample
.
metadata
.
description
stringByReplacingOccurrencesOfString
:
@" "
withString
:
@""
];
metadata
=
[
metadata
stringByReplacingOccurrencesOfString
:
@"
\r
"
withString
:
@""
];
metadata
=
[
metadata
stringByReplacingOccurrencesOfString
:
@"
\n
"
withString
:
@""
];
NSDictionary
*
elem
=
@{
@"value"
:
@
(
value
),
@"startDate"
:
@
(
startDateTimestamp
),
@"endDate"
:
@
(
endDateTimestamp
),
@"deviceName"
:
deviceName
,
@"deviceManufacturer"
:
deviceManufacturer
,
@"deviceHardware"
:
deviceHardwareVer
,
@"deviceSoftware"
:
deviceSoftwareVer
,
@"sourceName"
:
sourceName
,
@"sourceId"
:
sourceId
,
@"unit"
:
unit
.
description
,
@"uuid"
:
uuid
,
@"metadata"
:
metadata
};
[
data
addObject
:
elem
];
}
completion
(
data
,
error
);
});
}
};
HKSampleQuery
*
query
=
[[
HKSampleQuery
alloc
]
initWithSampleType
:
quantityType
predicate:
predicate
limit:
lim
sortDescriptors:
@[
timeSortDescriptor
]
resultsHandler:
handlerBlock
];
[
self
.
healthStore
executeQuery
:
query
];
}
...
...
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