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
8453d910
Commit
8453d910
authored
Jun 28, 2016
by
Greg Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added body_saveBodyMassIndex method and exported RCT saveBmi
parent
6e8ebb62
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
5 deletions
+30
-5
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h
+1
-0
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
+24
-5
RCTAppleHealthKit/RCTAppleHealthKit.m
RCTAppleHealthKit/RCTAppleHealthKit.m
+5
-0
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h
View file @
8453d910
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
-
(
void
)
body_saveWeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_saveWeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getLatestBodyMassIndex
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getLatestBodyMassIndex
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_saveBodyMassIndex
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getMostRecentHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getMostRecentHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_saveHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_saveHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
View file @
8453d910
...
@@ -40,19 +40,15 @@
...
@@ -40,19 +40,15 @@
-
(
void
)
body_saveWeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
-
(
void
)
body_saveWeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
{
double
weight
=
[[
input
objectForKey
:
@"weight"
]
doubleValue
];
double
weight
=
[[
input
objectForKey
:
@"weight"
]
doubleValue
];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
// HKUnit *poundUnit = [HKUnit poundUnit];
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
];
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
];
if
(
unit
==
nil
){
if
(
unit
==
nil
){
unit
=
[
HKUnit
poundUnit
];
unit
=
[
HKUnit
poundUnit
];
}
}
HKQuantity
*
weightQuantity
=
[
HKQuantity
quantityWithUnit
:
unit
doubleValue
:
weight
];
HKQuantity
*
weightQuantity
=
[
HKQuantity
quantityWithUnit
:
unit
doubleValue
:
weight
];
HKQuantityType
*
weightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierBodyMass
];
HKQuantityType
*
weightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierBodyMass
];
// NSDate *now = [NSDate date];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
HKQuantitySample
*
weightSample
=
[
HKQuantitySample
quantitySampleWithType
:
weightType
quantity
:
weightQuantity
startDate
:
sampleDate
endDate
:
sampleDate
];
HKQuantitySample
*
weightSample
=
[
HKQuantitySample
quantitySampleWithType
:
weightType
quantity
:
weightQuantity
startDate
:
sampleDate
endDate
:
sampleDate
];
[
self
.
healthStore
saveObject
:
weightSample
withCompletion
:
^
(
BOOL
success
,
NSError
*
error
)
{
[
self
.
healthStore
saveObject
:
weightSample
withCompletion
:
^
(
BOOL
success
,
NSError
*
error
)
{
...
@@ -93,6 +89,29 @@
...
@@ -93,6 +89,29 @@
}
}
-
(
void
)
body_saveBodyMassIndex
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
double
bmi
=
[
RCTAppleHealthKit
doubleValueFromOptions
:
input
];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
HKUnit
*
unit
=
[
HKUnit
countUnit
];
HKQuantity
*
bmiQuantity
=
[
HKQuantity
quantityWithUnit
:
unit
doubleValue
:
bmi
];
HKQuantityType
*
bmiType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierBodyMassIndex
];
HKQuantitySample
*
bmiSample
=
[
HKQuantitySample
quantitySampleWithType
:
bmiType
quantity
:
bmiQuantity
startDate
:
sampleDate
endDate
:
sampleDate
];
[
self
.
healthStore
saveObject
:
bmiSample
withCompletion
:
^
(
BOOL
success
,
NSError
*
error
)
{
if
(
!
success
)
{
NSLog
(
@"An error occured saving the bmi sample %@. In your app, try to handle this gracefully. The error was: %@."
,
bmiSample
,
error
);
callback
(@[
RCTMakeError
(
@"An error occured saving the bmi sample"
,
nil
,
nil
)]);
return
;
}
callback
(@[[
NSNull
null
],
@
(
bmi
)]);
}];
}
-
(
void
)
body_getMostRecentHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
-
(
void
)
body_getMostRecentHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
{
HKQuantityType
*
heightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierHeight
];
HKQuantityType
*
heightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierHeight
];
...
...
RCTAppleHealthKit/RCTAppleHealthKit.m
View file @
8453d910
...
@@ -56,6 +56,11 @@ RCT_EXPORT_METHOD(getLatestBmi:(NSDictionary *)input callback:(RCTResponseSender
...
@@ -56,6 +56,11 @@ RCT_EXPORT_METHOD(getLatestBmi:(NSDictionary *)input callback:(RCTResponseSender
[
self
body_getLatestBodyMassIndex
:
input
callback
:
callback
];
[
self
body_getLatestBodyMassIndex
:
input
callback
:
callback
];
}
}
RCT_EXPORT_METHOD
(
saveBmi
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
[
self
body_saveBodyMassIndex
:
input
callback
:
callback
];
}
RCT_EXPORT_METHOD
(
getLatestBodyFatPercentage
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
RCT_EXPORT_METHOD
(
getLatestBodyFatPercentage
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
{
...
...
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