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
0e8e8490
Commit
0e8e8490
authored
Jan 30, 2019
by
Furyou81
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get the activity
parent
bdb39228
Changes
14
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
462 additions
and
103 deletions
+462
-103
Constants/Permissions.js
Constants/Permissions.js
+2
-1
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h
+3
-1
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m
+2
-2
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
+5
-6
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
+2
-0
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
+46
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+15
-1
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+156
-38
RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h
RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h
+2
-0
RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m
RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m
+4
-2
RCTAppleHealthKit/RCTAppleHealthKit+Utils.h
RCTAppleHealthKit/RCTAppleHealthKit+Utils.h
+2
-1
RCTAppleHealthKit/RCTAppleHealthKit+Utils.m
RCTAppleHealthKit/RCTAppleHealthKit+Utils.m
+185
-50
RCTAppleHealthKit/RCTAppleHealthKit.h
RCTAppleHealthKit/RCTAppleHealthKit.h
+2
-0
RCTAppleHealthKit/RCTAppleHealthKit.m
RCTAppleHealthKit/RCTAppleHealthKit.m
+36
-1
No files found.
Constants/Permissions.js
View file @
0e8e8490
...
@@ -66,5 +66,6 @@ export const Permissions = {
...
@@ -66,5 +66,6 @@ export const Permissions = {
SleepAnalysis
:
"
SleepAnalysis
"
,
SleepAnalysis
:
"
SleepAnalysis
"
,
StepCount
:
"
StepCount
"
,
StepCount
:
"
StepCount
"
,
Steps
:
"
Steps
"
,
Steps
:
"
Steps
"
,
Weight
:
"
Weight
"
Weight
:
"
Weight
"
,
Workout
:
"
Workout
"
}
}
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.h
View file @
0e8e8490
...
@@ -3,8 +3,10 @@
...
@@ -3,8 +3,10 @@
// RCTAppleHealthKit
// RCTAppleHealthKit
//
//
// Created by Alexander Vallorosi on 4/27/17.
// Created by Alexander Vallorosi on 4/27/17.
// Copyright © 2017 Alexander Vallorosi. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
//
#import "RCTAppleHealthKit.h"
#import "RCTAppleHealthKit.h"
@interface
RCTAppleHealthKit
(
Methods_Activity
)
@interface
RCTAppleHealthKit
(
Methods_Activity
)
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Activity.m
View file @
0e8e8490
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
// RCTAppleHealthKit
// RCTAppleHealthKit
//
//
// Created by Alexander Vallorosi on 4/27/17.
// Created by Alexander Vallorosi on 4/27/17.
//
Copyright © 2017 Alexander Vallorosi. All rights reserved.
//
This source code is licensed under the MIT-style license found in the
//
//
LICENSE file in the root directory of this source tree.
#import "RCTAppleHealthKit+Methods_Activity.h"
#import "RCTAppleHealthKit+Methods_Activity.h"
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Queries.h"
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Body.m
View file @
0e8e8490
...
@@ -18,9 +18,9 @@
...
@@ -18,9 +18,9 @@
{
{
HKQuantityType
*
weightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierBodyMass
];
HKQuantityType
*
weightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierBodyMass
];
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
];
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
key
:
@"unit"
withDefault
:
[
HKUnit
gramUnitWithMetricPrefix
:
HKMetricPrefixKilo
]
];
if
(
unit
==
nil
){
if
(
unit
==
nil
){
unit
=
[
HKUnit
pound
Unit
];
unit
=
[
HKUnit
gram
Unit
];
}
}
[
self
fetchMostRecentQuantitySampleOfType
:
weightType
[
self
fetchMostRecentQuantitySampleOfType
:
weightType
...
@@ -33,7 +33,6 @@
...
@@ -33,7 +33,6 @@
else
{
else
{
// Determine the weight in the required unit.
// Determine the weight in the required unit.
double
usersWeight
=
[
mostRecentQuantity
doubleValueForUnit
:
unit
];
double
usersWeight
=
[
mostRecentQuantity
doubleValueForUnit
:
unit
];
NSDictionary
*
response
=
@{
NSDictionary
*
response
=
@{
@"value"
:
@
(
usersWeight
),
@"value"
:
@
(
usersWeight
),
@"startDate"
:
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
startDate
],
@"startDate"
:
[
RCTAppleHealthKit
buildISO8601StringFromDate
:
startDate
],
...
@@ -153,9 +152,9 @@
...
@@ -153,9 +152,9 @@
{
{
HKQuantityType
*
heightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierHeight
];
HKQuantityType
*
heightType
=
[
HKQuantityType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierHeight
];
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
]
;
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
key
:
@"unit"
withDefault
:
[
HKUnit
meterUnitWithMetricPrefix
:
HKMetricPrefixCenti
]];
;
if
(
unit
==
nil
){
if
(
unit
==
nil
){
unit
=
[
HKUnit
inch
Unit
];
unit
=
[
HKUnit
meter
Unit
];
}
}
[
self
fetchMostRecentQuantitySampleOfType
:
heightType
[
self
fetchMostRecentQuantitySampleOfType
:
heightType
...
@@ -219,7 +218,7 @@
...
@@ -219,7 +218,7 @@
double
height
=
[
RCTAppleHealthKit
doubleValueFromOptions
:
input
];
double
height
=
[
RCTAppleHealthKit
doubleValueFromOptions
:
input
];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
NSDate
*
sampleDate
=
[
RCTAppleHealthKit
dateFromOptionsDefaultNow
:
input
];
HKUnit
*
heightUnit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
]
;
HKUnit
*
heightUnit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
key
:
@"unit"
withDefault
:
[
HKUnit
inchUnit
]];
;
if
(
heightUnit
==
nil
){
if
(
heightUnit
==
nil
){
heightUnit
=
[
HKUnit
inchUnit
];
heightUnit
=
[
HKUnit
inchUnit
];
}
}
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
View file @
0e8e8490
...
@@ -12,6 +12,8 @@
...
@@ -12,6 +12,8 @@
@interface
RCTAppleHealthKit
(
Methods_Fitness
)
@interface
RCTAppleHealthKit
(
Methods_Fitness
)
-
(
void
)
fitness_getStepCountOnDay
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_getStepCountOnDay
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_getSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
;
-
(
void
)
fitness_getDailyStepSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_getDailyStepSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_saveSteps
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_saveSteps
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_initializeStepEventObserver
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_initializeStepEventObserver
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
View file @
0e8e8490
...
@@ -49,6 +49,52 @@
...
@@ -49,6 +49,52 @@
}];
}];
}
}
-
(
void
)
fitness_getSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
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
];
NSString
*
type
=
[
RCTAppleHealthKit
stringFromOptions
:
input
key
:
@"type"
withDefault
:
@"Walking"
];
NSDate
*
startDate
=
[
RCTAppleHealthKit
dateFromOptions
:
input
key
:
@"startDate"
withDefault
:
[
NSDate
date
]];
NSDate
*
endDate
=
[
RCTAppleHealthKit
dateFromOptions
:
input
key
:
@"endDate"
withDefault
:
[
NSDate
date
]];
NSPredicate
*
predicate
=
[
HKQuery
predicateForSamplesWithStartDate
:
startDate
endDate
:
endDate
options
:
HKQueryOptionStrictStartDate
];
HKSampleType
*
samplesType
=
[
RCTAppleHealthKit
hkQuantityTypeFromString
:
type
];
if
([
type
isEqual
:
@"Running"
]
||
[
type
isEqual
:
@"Cycling"
])
{
unit
=
[
HKUnit
mileUnit
];
}
NSLog
(
@"error getting samples: %@"
,
[
samplesType
identifier
]);
[
self
fetchSamplesOfType
:
samplesType
unit:
unit
predicate:
predicate
ascending:
ascending
limit:
limit
completion:
^
(
NSArray
*
results
,
NSError
*
error
)
{
if
(
results
){
callback
(@[[
NSNull
null
],
results
]);
return
;
}
else
{
NSLog
(
@"error getting samples: %@"
,
error
);
callback
(@[
RCTMakeError
(
@"error getting samples"
,
nil
,
nil
)]);
return
;
}
}];
}
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
{
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
key
:
@"unit"
withDefault
:
[
HKUnit
countUnit
]];
NSString
*
type
=
[
RCTAppleHealthKit
stringFromOptions
:
input
key
:
@"type"
withDefault
:
@"Walking"
];
HKSampleType
*
samplesType
=
[
RCTAppleHealthKit
hkQuantityTypeFromString
:
type
];
if
([
type
isEqual
:
@"Running"
]
||
[
type
isEqual
:
@"Cycling"
])
{
unit
=
[
HKUnit
mileUnit
];
}
[
self
setObserverForType
:
samplesType
unit
:
unit
];
}
-
(
void
)
fitness_getDailyStepSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
-
(
void
)
fitness_getDailyStepSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
{
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
0e8e8490
...
@@ -19,6 +19,18 @@
...
@@ -19,6 +19,18 @@
startDate
:(
NSDate
*
)
startDate
startDate
:(
NSDate
*
)
startDate
endDate
:(
NSDate
*
)
endDate
endDate
:(
NSDate
*
)
endDate
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
-
(
void
)
fetchSamplesOfType
:(
HKSampleType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
-
(
void
)
setObserverForType
:(
HKSampleType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
;
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
predicate
:(
NSPredicate
*
)
predicate
...
@@ -46,6 +58,8 @@
...
@@ -46,6 +58,8 @@
ascending
:(
BOOL
)
asc
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completionHandler
;
-
(
void
)
fetchSleepCategorySamplesForPredicate
:(
NSPredicate
*
)
predicate
-
(
void
)
fetchSleepCategorySamplesForPredicate
:(
NSPredicate
*
)
predicate
limit
:(
NSUInteger
)
lim
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
0e8e8490
This diff is collapsed.
Click to expand it.
RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h
View file @
0e8e8490
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
@interface
RCTAppleHealthKit
(
TypesAndPermissions
)
@interface
RCTAppleHealthKit
(
TypesAndPermissions
)
-
(
NSDictionary
*
)
readPermsDict
;
-
(
NSDictionary
*
)
writePermsDict
;
-
(
NSSet
*
)
getReadPermsFromOptions
:(
NSArray
*
)
options
;
-
(
NSSet
*
)
getReadPermsFromOptions
:(
NSArray
*
)
options
;
-
(
NSSet
*
)
getWritePermsFromOptions
:(
NSArray
*
)
options
;
-
(
NSSet
*
)
getWritePermsFromOptions
:(
NSArray
*
)
options
;
...
...
RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m
View file @
0e8e8490
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
// RCTAppleHealthKit
// RCTAppleHealthKit
//
//
// Created by Greg Wilson on 2016-06-26.
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
//
#import "RCTAppleHealthKit+TypesAndPermissions.h"
#import "RCTAppleHealthKit+TypesAndPermissions.h"
...
@@ -49,6 +50,8 @@
...
@@ -49,6 +50,8 @@
@"SleepAnalysis"
:
[
HKObjectType
categoryTypeForIdentifier
:
HKCategoryTypeIdentifierSleepAnalysis
],
@"SleepAnalysis"
:
[
HKObjectType
categoryTypeForIdentifier
:
HKCategoryTypeIdentifierSleepAnalysis
],
// Mindfulness
// Mindfulness
@"MindfulSession"
:
[
HKObjectType
categoryTypeForIdentifier
:
HKCategoryTypeIdentifierMindfulSession
],
@"MindfulSession"
:
[
HKObjectType
categoryTypeForIdentifier
:
HKCategoryTypeIdentifierMindfulSession
],
//workouts
@"Workout"
:
[
HKObjectType
workoutType
],
};
};
return
readPerms
;
return
readPerms
;
}
}
...
@@ -118,7 +121,6 @@
...
@@ -118,7 +121,6 @@
return
writePerms
;
return
writePerms
;
}
}
// Returns HealthKit read permissions from options array
// Returns HealthKit read permissions from options array
-
(
NSSet
*
)
getReadPermsFromOptions
:(
NSArray
*
)
options
{
-
(
NSSet
*
)
getReadPermsFromOptions
:(
NSArray
*
)
options
{
NSDictionary
*
readPermDict
=
[
self
readPermsDict
];
NSDictionary
*
readPermDict
=
[
self
readPermsDict
];
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Utils.h
View file @
0e8e8490
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
+
(
NSDate
*
)
startDateFromOptions
:(
NSDictionary
*
)
options
;
+
(
NSDate
*
)
startDateFromOptions
:(
NSDictionary
*
)
options
;
+
(
NSDate
*
)
endDateFromOptions
:(
NSDictionary
*
)
options
;
+
(
NSDate
*
)
endDateFromOptions
:(
NSDictionary
*
)
options
;
+
(
NSDate
*
)
endDateFromOptionsDefaultNow
:(
NSDictionary
*
)
options
;
+
(
NSDate
*
)
endDateFromOptionsDefaultNow
:(
NSDictionary
*
)
options
;
+
(
HK
Unit
*
)
hkUnitFromOptions
:(
NSDictionary
*
)
options
;
+
(
HK
SampleType
*
)
hkQuantityTypeFromString
:(
NSString
*
)
type
;
+
(
HKUnit
*
)
hkUnitFromOptions
:(
NSDictionary
*
)
options
key
:(
NSString
*
)
key
withDefault
:(
HKUnit
*
)
defaultValue
;
+
(
HKUnit
*
)
hkUnitFromOptions
:(
NSDictionary
*
)
options
key
:(
NSString
*
)
key
withDefault
:(
HKUnit
*
)
defaultValue
;
+
(
NSUInteger
)
uintFromOptions
:(
NSDictionary
*
)
options
key
:(
NSString
*
)
key
withDefault
:(
NSUInteger
)
defaultValue
;
+
(
NSUInteger
)
uintFromOptions
:(
NSDictionary
*
)
options
key
:(
NSString
*
)
key
withDefault
:(
NSUInteger
)
defaultValue
;
...
@@ -33,5 +33,6 @@
...
@@ -33,5 +33,6 @@
+
(
bool
)
boolFromOptions
:(
NSDictionary
*
)
options
key
:(
NSString
*
)
key
withDefault
:(
bool
)
defaultValue
;
+
(
bool
)
boolFromOptions
:(
NSDictionary
*
)
options
key
:(
NSString
*
)
key
withDefault
:(
bool
)
defaultValue
;
+
(
NSMutableArray
*
)
reverseNSMutableArray
:(
NSMutableArray
*
)
array
;
+
(
NSMutableArray
*
)
reverseNSMutableArray
:(
NSMutableArray
*
)
array
;
+
(
NSString
*
)
stringForHKWorkoutActivityType
:(
int
)
enumValue
;
@end
@end
RCTAppleHealthKit/RCTAppleHealthKit+Utils.m
View file @
0e8e8490
...
@@ -124,56 +124,20 @@
...
@@ -124,56 +124,20 @@
return
date
;
return
date
;
}
}
// ==========
+
(
HKSampleType
*
)
hkQuantityTypeFromString
:(
NSString
*
)
type
{
// DEPRECATED
if
([
type
isEqual
:
@"Walking"
])
{
// ==========
return
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierStepCount
];
+
(
HKUnit
*
)
hkUnitFromOptions
:(
NSDictionary
*
)
options
{
}
else
if
([
type
isEqual
:
@"StairClimbing"
])
{
NSString
*
unitString
=
[
options
objectForKey
:
@"unit"
];
return
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierFlightsClimbed
];
HKUnit
*
theUnit
;
}
else
if
([
type
isEqual
:
@"Running"
]){
return
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierDistanceWalkingRunning
];
if
([
unitString
isEqualToString
:
@"gram"
]){
}
else
if
([
type
isEqual
:
@"Cycling"
]){
theUnit
=
[
HKUnit
gramUnit
];
return
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierDistanceCycling
];
}
}
else
if
([
type
isEqual
:
@"Swimming"
]){
if
([
unitString
isEqualToString
:
@"pound"
]){
return
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierDistanceSwimming
];
theUnit
=
[
HKUnit
poundUnit
];
}
}
// default [type isEqual:@"Workout"])
if
([
unitString
isEqualToString
:
@"meter"
]){
return
[
HKObjectType
workoutType
];
theUnit
=
[
HKUnit
meterUnit
];
}
if
([
unitString
isEqualToString
:
@"mile"
]){
theUnit
=
[
HKUnit
mileUnit
];
}
if
([
unitString
isEqualToString
:
@"inch"
]){
theUnit
=
[
HKUnit
inchUnit
];
}
if
([
unitString
isEqualToString
:
@"foot"
]){
theUnit
=
[
HKUnit
footUnit
];
}
if
([
unitString
isEqualToString
:
@"second"
]){
theUnit
=
[
HKUnit
secondUnit
];
}
if
([
unitString
isEqualToString
:
@"minute"
]){
theUnit
=
[
HKUnit
minuteUnit
];
}
if
([
unitString
isEqualToString
:
@"hour"
]){
theUnit
=
[
HKUnit
hourUnit
];
}
if
([
unitString
isEqualToString
:
@"day"
]){
theUnit
=
[
HKUnit
dayUnit
];
}
if
([
unitString
isEqualToString
:
@"joule"
]){
theUnit
=
[
HKUnit
jouleUnit
];
}
if
([
unitString
isEqualToString
:
@"calorie"
]){
theUnit
=
[
HKUnit
calorieUnit
];
}
if
([
unitString
isEqualToString
:
@"count"
]){
theUnit
=
[
HKUnit
countUnit
];
}
if
([
unitString
isEqualToString
:
@"percent"
]){
theUnit
=
[
HKUnit
percentUnit
];
}
return
theUnit
;
}
}
...
@@ -184,12 +148,21 @@
...
@@ -184,12 +148,21 @@
if
([
unitString
isEqualToString
:
@"gram"
]){
if
([
unitString
isEqualToString
:
@"gram"
]){
theUnit
=
[
HKUnit
gramUnit
];
theUnit
=
[
HKUnit
gramUnit
];
}
}
if
([
unitString
isEqualToString
:
@"kg"
]){
theUnit
=
[
HKUnit
gramUnitWithMetricPrefix
:
HKMetricPrefixKilo
];
}
if
([
unitString
isEqualToString
:
@"stone"
]){
theUnit
=
[
HKUnit
stoneUnit
];
}
if
([
unitString
isEqualToString
:
@"pound"
]){
if
([
unitString
isEqualToString
:
@"pound"
]){
theUnit
=
[
HKUnit
poundUnit
];
theUnit
=
[
HKUnit
poundUnit
];
}
}
if
([
unitString
isEqualToString
:
@"meter"
]){
if
([
unitString
isEqualToString
:
@"meter"
]){
theUnit
=
[
HKUnit
meterUnit
];
theUnit
=
[
HKUnit
meterUnit
];
}
}
if
([
unitString
isEqualToString
:
@"cm"
]){
theUnit
=
[
HKUnit
meterUnitWithMetricPrefix
:
HKMetricPrefixCenti
];
}
if
([
unitString
isEqualToString
:
@"inch"
]){
if
([
unitString
isEqualToString
:
@"inch"
]){
theUnit
=
[
HKUnit
inchUnit
];
theUnit
=
[
HKUnit
inchUnit
];
}
}
...
@@ -321,4 +294,166 @@
...
@@ -321,4 +294,166 @@
return
array
;
return
array
;
}
}
+
(
NSString
*
)
stringForHKWorkoutActivityType
:(
int
)
enumValue
{
switch
(
enumValue
){
case
HKWorkoutActivityTypeAmericanFootball
:
return
@"AmericanFootball"
;
case
HKWorkoutActivityTypeArchery
:
return
@"Archery"
;
case
HKWorkoutActivityTypeAustralianFootball
:
return
@"AustralianFootball"
;
case
HKWorkoutActivityTypeBadminton
:
return
@"Badminton"
;
case
HKWorkoutActivityTypeBaseball
:
return
@"Baseball"
;
case
HKWorkoutActivityTypeBasketball
:
return
@"Basketball"
;
case
HKWorkoutActivityTypeBowling
:
return
@"Bowling"
;
case
HKWorkoutActivityTypeBoxing
:
return
@"Boxing"
;
case
HKWorkoutActivityTypeClimbing
:
return
@"Climbing"
;
case
HKWorkoutActivityTypeCricket
:
return
@"Cricket"
;
case
HKWorkoutActivityTypeCrossTraining
:
return
@"CrossTraining"
;
case
HKWorkoutActivityTypeCurling
:
return
@"Curling"
;
case
HKWorkoutActivityTypeCycling
:
return
@"Cycling"
;
case
HKWorkoutActivityTypeDance
:
return
@"Dance"
;
case
HKWorkoutActivityTypeDanceInspiredTraining
:
return
@"DanceInspiredTraining"
;
case
HKWorkoutActivityTypeElliptical
:
return
@"Elliptical"
;
case
HKWorkoutActivityTypeEquestrianSports
:
return
@"EquestrianSports"
;
case
HKWorkoutActivityTypeFencing
:
return
@"Fencing"
;
case
HKWorkoutActivityTypeFishing
:
return
@"Fishing"
;
case
HKWorkoutActivityTypeFunctionalStrengthTraining
:
return
@"FunctionalStrengthTraining"
;
case
HKWorkoutActivityTypeGolf
:
return
@"Golf"
;
case
HKWorkoutActivityTypeGymnastics
:
return
@"Gymnastics"
;
case
HKWorkoutActivityTypeHandball
:
return
@"Handball"
;
case
HKWorkoutActivityTypeHiking
:
return
@"Hiking"
;
case
HKWorkoutActivityTypeHockey
:
return
@"Hockey"
;
case
HKWorkoutActivityTypeHunting
:
return
@"Hunting"
;
case
HKWorkoutActivityTypeLacrosse
:
return
@"Lacrosse"
;
case
HKWorkoutActivityTypeMartialArts
:
return
@"MartialArts"
;
case
HKWorkoutActivityTypeMindAndBody
:
return
@"MindAndBody"
;
case
HKWorkoutActivityTypeMixedMetabolicCardioTraining
:
return
@"MixedMetabolicCardioTraining"
;
case
HKWorkoutActivityTypePaddleSports
:
return
@"PaddleSports"
;
case
HKWorkoutActivityTypePlay
:
return
@"Play"
;
case
HKWorkoutActivityTypePreparationAndRecovery
:
return
@"PreparationAndRecovery"
;
case
HKWorkoutActivityTypeRacquetball
:
return
@"Racquetball"
;
case
HKWorkoutActivityTypeRowing
:
return
@"Rowing"
;
case
HKWorkoutActivityTypeRugby
:
return
@"Rugby"
;
case
HKWorkoutActivityTypeRunning
:
return
@"Running"
;
case
HKWorkoutActivityTypeSailing
:
return
@"Sailing"
;
case
HKWorkoutActivityTypeSkatingSports
:
return
@"SkatingSports"
;
case
HKWorkoutActivityTypeSnowSports
:
return
@"SnowSports"
;
case
HKWorkoutActivityTypeSoccer
:
return
@"Soccer"
;
case
HKWorkoutActivityTypeSoftball
:
return
@"Softball"
;
case
HKWorkoutActivityTypeSquash
:
return
@"Squash"
;
case
HKWorkoutActivityTypeStairClimbing
:
return
@"StairClimbing"
;
case
HKWorkoutActivityTypeSurfingSports
:
return
@"SurfingSports"
;
case
HKWorkoutActivityTypeSwimming
:
return
@"Swimming"
;
case
HKWorkoutActivityTypeTableTennis
:
return
@"TableTennis"
;
case
HKWorkoutActivityTypeTennis
:
return
@"Tennis"
;
case
HKWorkoutActivityTypeTrackAndField
:
return
@"TrackAndField"
;
case
HKWorkoutActivityTypeTraditionalStrengthTraining
:
return
@"TraditionalStrengthTraining"
;
case
HKWorkoutActivityTypeVolleyball
:
return
@"Volleyball"
;
case
HKWorkoutActivityTypeWalking
:
return
@"Walking"
;
case
HKWorkoutActivityTypeWaterFitness
:
return
@"WaterFitness"
;
case
HKWorkoutActivityTypeWaterPolo
:
return
@"WaterPolo"
;
case
HKWorkoutActivityTypeWaterSports
:
return
@"WaterSports"
;
case
HKWorkoutActivityTypeWrestling
:
return
@"Wrestling"
;
case
HKWorkoutActivityTypeYoga
:
return
@"Yoga"
;
case
HKWorkoutActivityTypeOther
:
return
@"Other"
;
case
HKWorkoutActivityTypeBarre
:
return
@"Barre"
;
case
HKWorkoutActivityTypeCoreTraining
:
return
@"CoreTraining"
;
case
HKWorkoutActivityTypeCrossCountrySkiing
:
return
@"CrossCountrySkiing"
;
case
HKWorkoutActivityTypeDownhillSkiing
:
return
@"DownhillSkiing"
;
case
HKWorkoutActivityTypeFlexibility
:
return
@"Flexibility"
;
case
HKWorkoutActivityTypeHighIntensityIntervalTraining
:
return
@"HighIntensityIntervalTraining"
;
case
HKWorkoutActivityTypeJumpRope
:
return
@"JumpRope"
;
case
HKWorkoutActivityTypeKickboxing
:
return
@"Kickboxing"
;
case
HKWorkoutActivityTypePilates
:
return
@"Pilates"
;
case
HKWorkoutActivityTypeSnowboarding
:
return
@"Snowboarding"
;
case
HKWorkoutActivityTypeStairs
:
return
@"Stairs"
;
case
HKWorkoutActivityTypeStepTraining
:
return
@"StepTraining"
;
case
HKWorkoutActivityTypeWheelchairWalkPace
:
return
@"WheelchairWalkPace"
;
case
HKWorkoutActivityTypeWheelchairRunPace
:
return
@"WheelchairRunPace"
;
case
HKWorkoutActivityTypeTaiChi
:
return
@"TaiChi"
;
case
HKWorkoutActivityTypeMixedCardio
:
return
@"MixedCardio"
;
case
HKWorkoutActivityTypeHandCycling
:
return
@"HandCycling"
;
default:
{
NSException
*
e
=
[
NSException
exceptionWithName:
@"HKWorkoutActivityType InvalidValue"
reason:
@"HKWorkoutActivityType can only have a value from the HKWorkoutActivityType enum"
userInfo:
nil
];
@throw
e
;
}
}
}
@end
@end
RCTAppleHealthKit/RCTAppleHealthKit.h
View file @
0e8e8490
...
@@ -16,9 +16,11 @@
...
@@ -16,9 +16,11 @@
@interface
RCTAppleHealthKit
:
NSObject
<
RCTBridgeModule
>
@interface
RCTAppleHealthKit
:
NSObject
<
RCTBridgeModule
>
@property
(
nonatomic
)
HKHealthStore
*
healthStore
;
@property
(
nonatomic
)
HKHealthStore
*
healthStore
;
@property
BOOL
isSync
;
-
(
void
)
isHealthKitAvailable
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
isHealthKitAvailable
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
initializeHealthKit
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
initializeHealthKit
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
checkPermission
:(
NSString
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
getModuleInfo
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
getModuleInfo
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
@end
@end
RCTAppleHealthKit/RCTAppleHealthKit.m
View file @
0e8e8490
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
// RCTAppleHealthKit
// RCTAppleHealthKit
//
//
// Created by Greg Wilson on 2016-06-26.
// Created by Greg Wilson on 2016-06-26.
// Copyright © 2016 Greg Wilson. All rights reserved.
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
//
#import "RCTAppleHealthKit.h"
#import "RCTAppleHealthKit.h"
...
@@ -23,6 +24,7 @@
...
@@ -23,6 +24,7 @@
#import <React/RCTEventDispatcher.h>
#import <React/RCTEventDispatcher.h>
@implementation
RCTAppleHealthKit
@implementation
RCTAppleHealthKit
@synthesize
bridge
=
_bridge
;
@synthesize
bridge
=
_bridge
;
RCT_EXPORT_MODULE
();
RCT_EXPORT_MODULE
();
...
@@ -37,6 +39,11 @@ RCT_EXPORT_METHOD(initHealthKit:(NSDictionary *)input callback:(RCTResponseSende
...
@@ -37,6 +39,11 @@ RCT_EXPORT_METHOD(initHealthKit:(NSDictionary *)input callback:(RCTResponseSende
[
self
initializeHealthKit
:
input
callback
:
callback
];
[
self
initializeHealthKit
:
input
callback
:
callback
];
}
}
RCT_EXPORT_METHOD
(
checkSharePermission
:
(
NSString
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
[
self
checkPermission
:
input
callback
:
callback
];
}
RCT_EXPORT_METHOD
(
initStepCountObserver
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
RCT_EXPORT_METHOD
(
initStepCountObserver
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
{
[
self
fitness_initializeStepEventObserver
:
input
callback
:
callback
];
[
self
fitness_initializeStepEventObserver
:
input
callback
:
callback
];
...
@@ -107,6 +114,17 @@ RCT_EXPORT_METHOD(getStepCount:(NSDictionary *)input callback:(RCTResponseSender
...
@@ -107,6 +114,17 @@ RCT_EXPORT_METHOD(getStepCount:(NSDictionary *)input callback:(RCTResponseSender
[
self
fitness_getStepCountOnDay
:
input
callback
:
callback
];
[
self
fitness_getStepCountOnDay
:
input
callback
:
callback
];
}
}
RCT_EXPORT_METHOD
(
getSamples
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
[
self
fitness_getSamples
:
input
callback
:
callback
];
}
RCT_EXPORT_METHOD
(
setObserver
:
(
NSDictionary
*
)
input
)
{
[
self
fitness_setObserver
:
input
];
}
RCT_EXPORT_METHOD
(
getDailyStepCountSamples
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
RCT_EXPORT_METHOD
(
getDailyStepCountSamples
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
{
[
self
fitness_getDailyStepSamples
:
input
callback
:
callback
];
[
self
fitness_getDailyStepSamples
:
input
callback
:
callback
];
...
@@ -268,6 +286,23 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse
...
@@ -268,6 +286,23 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse
}
}
}
}
-
(
void
)
checkPermission
:(
NSString
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
self
.
healthStore
=
[[
HKHealthStore
alloc
]
init
];
if
([
HKHealthStore
isHealthDataAvailable
])
{
HKObjectType
*
val
=
[[
self
writePermsDict
]
objectForKey
:
input
];
if
([
self
.
healthStore
authorizationStatusForType
:
val
]
==
HKAuthorizationStatusSharingAuthorized
)
{
callback
(@[[
NSNull
null
],
@true
]);
}
else
{
callback
(@[[
NSNull
null
],
@false
]);
}
}
else
{
callback
(@[
RCTMakeError
(
@"HealthKit data is not available"
,
nil
,
nil
)]);
}
}
-
(
void
)
getModuleInfo
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
-
(
void
)
getModuleInfo
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
{
NSDictionary
*
info
=
@{
NSDictionary
*
info
=
@{
...
...
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