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
08ea5bef
Commit
08ea5bef
authored
Apr 14, 2019
by
Andrew Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add saveBodyFatPercentage
parent
8c189e9c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
0 deletions
+50
-0
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h
+2
-0
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
+24
-0
RCTAppleHealthKit/RCTAppleHealthKit.m
RCTAppleHealthKit/RCTAppleHealthKit.m
+5
-0
README.md
README.md
+2
-0
docs/saveBodyFatPercentage().md
docs/saveBodyFatPercentage().md
+17
-0
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.h
View file @
08ea5bef
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
-
(
void
)
body_saveHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_saveHeight
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getLatestBodyFatPercentage
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getLatestBodyFatPercentage
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_saveBodyFatPercentage
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getLatestLeanBodyMass
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
body_getLatestLeanBodyMass
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
@end
@end
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
View file @
08ea5bef
...
@@ -257,6 +257,30 @@
...
@@ -257,6 +257,30 @@
}
}
-
(
void
)
body_saveBodyFatPercentage
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
double
percentage
=
[
RCTAppleHealthKit
doubleValueFromOptions
:
input
];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
HKUnit
*
unit
=
[
HKUnit
percentUnit
];
percentage
=
percentage
/
100
;
HKQuantity
*
bodyFatPercentQuantity
=
[
HKQuantity
quantityWithUnit
:
unit
doubleValue
:
percentage
];
HKQuantityType
*
bodyFatPercentType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierBodyFatPercentage
];
HKQuantitySample
*
bodyFatPercentSample
=
[
HKQuantitySample
quantitySampleWithType
:
bodyFatPercentType
quantity
:
bodyFatPercentQuantity
startDate
:
sampleDate
endDate
:
sampleDate
];
[
self
.
healthStore
saveObject
:
bodyFatPercentSample
withCompletion
:
^
(
BOOL
success
,
NSError
*
error
)
{
if
(
!
success
)
{
NSLog
(
@"error saving body fat percent sample: %@"
,
error
);
callback
(@[
RCTMakeError
(
@"error saving body fat percent sample"
,
error
,
nil
)]);
return
;
}
callback
(@[[
NSNull
null
],
@
(
percentage
)]);
}];
}
-
(
void
)
body_getLatestLeanBodyMass
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
-
(
void
)
body_getLatestLeanBodyMass
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
{
HKQuantityType
*
leanBodyMassType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierLeanBodyMass
];
HKQuantityType
*
leanBodyMassType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierLeanBodyMass
];
...
...
RCTAppleHealthKit/RCTAppleHealthKit.m
View file @
08ea5bef
...
@@ -99,6 +99,11 @@ RCT_EXPORT_METHOD(getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCT
...
@@ -99,6 +99,11 @@ RCT_EXPORT_METHOD(getLatestBodyFatPercentage:(NSDictionary *)input callback:(RCT
[
self
body_getLatestBodyFatPercentage
:
input
callback
:
callback
];
[
self
body_getLatestBodyFatPercentage
:
input
callback
:
callback
];
}
}
RCT_EXPORT_METHOD
(
saveBodyFatPercentage
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
[
self
body_saveBodyFatPercentage
:
input
callback
:
callback
];
}
RCT_EXPORT_METHOD
(
getLatestLeanBodyMass
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
RCT_EXPORT_METHOD
(
getLatestLeanBodyMass
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
{
[
self
body_getLatestLeanBodyMass
:
input
callback
:
callback
];
[
self
body_getLatestLeanBodyMass
:
input
callback
:
callback
];
...
...
README.md
View file @
08ea5bef
...
@@ -142,6 +142,7 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) =>
...
@@ -142,6 +142,7 @@ AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) =>
*
[
saveMindfulSession
](
/docs/saveMindfulSession(
)
.md)
*
[
saveMindfulSession
](
/docs/saveMindfulSession(
)
.md)
*
[
saveWeight
](
/docs/saveWeight(
)
.md)
*
[
saveWeight
](
/docs/saveWeight(
)
.md)
*
[
saveSteps
](
/docs/saveSteps(
)
.md)
*
[
saveSteps
](
/docs/saveSteps(
)
.md)
*
[
saveBodyFatPercentage
](
/docs/saveBodyFatPercentage(
)
.md)
*
[
References
](
#references
)
*
[
References
](
#references
)
## Supported Apple Permissions
## Supported Apple Permissions
...
@@ -171,6 +172,7 @@ The available Healthkit permissions to use with `initHealthKit`
...
@@ -171,6 +172,7 @@ The available Healthkit permissions to use with `initHealthKit`
| StepCount |
[
HKQuantityTypeIdentifierStepCount
](
https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierstepcount?language=objc
)
| ✓ | ✓ |
| StepCount |
[
HKQuantityTypeIdentifierStepCount
](
https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierstepcount?language=objc
)
| ✓ | ✓ |
| Steps |
[
HKQuantityTypeIdentifierSteps
](
https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifiersteps?language=objc
)
| ✓ | ✓ |
| Steps |
[
HKQuantityTypeIdentifierSteps
](
https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifiersteps?language=objc
)
| ✓ | ✓ |
| Weight |
[
HKQuantityTypeIdentifierBodyMass
](
https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodymass?language=objc
)
| ✓ | ✓ |
| Weight |
[
HKQuantityTypeIdentifierBodyMass
](
https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodymass?language=objc
)
| ✓ | ✓ |
| BodyFatPercentage |
[
HKQuantityTypeIdentifierBodyFatPercentage
](
https://developer.apple.com/reference/Healthkit/hkquantitytypeidentifierbodyfatpercentage?language=objc
)
| ✓ | ✓ |
These permissions are exported as constants of the
`rn-apple-healthkit`
module.
These permissions are exported as constants of the
`rn-apple-healthkit`
module.
...
...
docs/saveBodyFatPercentage().md
0 → 100644
View file @
08ea5bef
save a percentage body fat value to Healthkit
`saveBodyFatPercentage`
accepts an options object containing a percent value:
```
javascript
let
options
=
{
value
:
16.7
// 16.7%
}
```
```
javascript
AppleHealthKit
.
saveBodyFatPercentage
(
options
:
Object
,
(
err
:
Object
,
results
:
Object
)
=>
{
if
(
err
)
{
return
;
}
// body fat percentage successfully saved
});
```
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