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
6e8ebb62
Commit
6e8ebb62
authored
Jun 28, 2016
by
Greg Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated body_saveWeight to use unit and date from options, if available
parent
edf44bcf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
17 deletions
+11
-17
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
+11
-17
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
View file @
6e8ebb62
...
...
@@ -30,9 +30,7 @@
}
else
{
// Determine the weight in the required unit.
// HKUnit *weightUnit = [HKUnit poundUnit];
double
usersWeight
=
[
mostRecentQuantity
doubleValueForUnit
:
unit
];
callback
(@[[
NSNull
null
],
@
(
usersWeight
)]);
}
}];
...
...
@@ -43,13 +41,19 @@
{
double
weight
=
[[
input
objectForKey
:
@"weight"
]
doubleValue
];
HKUnit
*
poundUnit
=
[
HKUnit
poundUnit
];
HKQuantity
*
weightQuantity
=
[
HKQuantity
quantityWithUnit
:
poundUnit
doubleValue
:
weight
];
// HKUnit *poundUnit = [HKUnit poundUnit];
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
];
if
(
unit
==
nil
){
unit
=
[
HKUnit
poundUnit
];
}
HKQuantity
*
weightQuantity
=
[
HKQuantity
quantityWithUnit
:
unit
doubleValue
:
weight
];
HKQuantityType
*
weightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierBodyMass
];
NSDate
*
now
=
[
NSDate
date
];
// NSDate *now = [NSDate date];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
HKQuantitySample
*
weightSample
=
[
HKQuantitySample
quantitySampleWithType
:
weightType
quantity
:
weightQuantity
startDate
:
now
endDate
:
now
];
HKQuantitySample
*
weightSample
=
[
HKQuantitySample
quantitySampleWithType
:
weightType
quantity
:
weightQuantity
startDate
:
sampleDate
endDate
:
sampleDate
];
[
self
.
healthStore
saveObject
:
weightSample
withCompletion
:
^
(
BOOL
success
,
NSError
*
error
)
{
if
(
!
success
)
{
...
...
@@ -104,10 +108,8 @@
callback
(@[
RCTMakeError
(
@"Either an error occured fetching the user's height information or none has been stored yet. In your app, try to handle this gracefully."
,
nil
,
nil
)]);
}
else
{
// Determine the weight in the required unit.
// HKUnit *heightUnit = [HKUnit inchUnit];
// Determine the height in the required unit.
double
usersHeight
=
[
mostRecentQuantity
doubleValueForUnit
:
unit
];
callback
(@[[
NSNull
null
],
@
(
usersHeight
)]);
}
}];
...
...
@@ -116,24 +118,16 @@
-
(
void
)
body_saveHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
// NSNumber *valueFromOptions = [RCTAppleHealthKit numericValueFromOptions:input];
// double height = [[input objectForKey:@"value"] doubleValue];
double
height
=
[
RCTAppleHealthKit
doubleValueFromOptions
:
input
];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
// HKUnit *heightUnit = [HKUnit inchUnit];
HKUnit
*
heightUnit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
];
if
(
heightUnit
==
nil
){
heightUnit
=
[
HKUnit
inchUnit
];
}
HKQuantity
*
heightQuantity
=
[
HKQuantity
quantityWithUnit
:
heightUnit
doubleValue
:
height
];
HKQuantityType
*
heightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierHeight
];
// NSDate *now = [NSDate date];
// HKQuantitySample *heightSample = [HKQuantitySample quantitySampleWithType:heightType quantity:heightQuantity startDate:now endDate:now];
HKQuantitySample
*
heightSample
=
[
HKQuantitySample
quantitySampleWithType
:
heightType
quantity
:
heightQuantity
startDate
:
sampleDate
endDate
:
sampleDate
];
[
self
.
healthStore
saveObject
:
heightSample
withCompletion
:
^
(
BOOL
success
,
NSError
*
error
)
{
...
...
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