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
f51978cc
Commit
f51978cc
authored
Feb 08, 2018
by
Evgenii Evstropov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raw version of observers
parent
e2aa87df
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
1 deletion
+102
-1
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
+1
-0
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
+25
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+7
-0
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+62
-1
RCTAppleHealthKit/RCTAppleHealthKit.h
RCTAppleHealthKit/RCTAppleHealthKit.h
+1
-0
RCTAppleHealthKit/RCTAppleHealthKit.m
RCTAppleHealthKit/RCTAppleHealthKit.m
+6
-0
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
View file @
f51978cc
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
-
(
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_getSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
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 @
f51978cc
...
@@ -91,6 +91,31 @@
...
@@ -91,6 +91,31 @@
}];
}];
}
}
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
key
:
@"unit"
withDefault
:
[
HKUnit
countUnit
]];
NSString
*
type
=
[
RCTAppleHealthKit
stringFromOptions
:
input
key
:
@"type"
withDefault
:
@"Walking"
];
HKSampleType
*
samplesType
=
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierStepCount
];
if
([
type
isEqual
:
@"Walking"
])
{
samplesType
=
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierStepCount
];
}
else
if
([
type
isEqual
:
@"StairClimbing"
])
{
samplesType
=
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierFlightsClimbed
];
}
else
if
([
type
isEqual
:
@"Running"
]){
samplesType
=
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierDistanceWalkingRunning
];
unit
=
[
HKUnit
mileUnit
];
}
else
if
([
type
isEqual
:
@"Cycling"
]){
samplesType
=
[
HKObjectType
quantityTypeForIdentifier
:
HKQuantityTypeIdentifierDistanceCycling
];
unit
=
[
HKUnit
mileUnit
];
}
else
if
([
type
isEqual
:
@"Workout"
]){
samplesType
=
[
HKObjectType
workoutType
];
}
[
self
setObserverForType
:
samplesType
unit
:
unit
completion
:^
(
NSArray
*
results
,
NSError
*
error
)
{
callback
(@[[
NSNull
null
],
results
]);
}];
}
-
(
void
)
fitness_getDailyStepSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
-
(
void
)
fitness_getDailyStepSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
{
{
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
f51978cc
...
@@ -18,12 +18,19 @@
...
@@ -18,12 +18,19 @@
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
-
(
void
)
fetchSamplesOfType
:(
HKSampleType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
predicate
:(
NSPredicate
*
)
predicate
ascending
:(
BOOL
)
asc
ascending
:(
BOOL
)
asc
limit
:(
NSUInteger
)
lim
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
-
(
void
)
setObserverForType
:(
HKSampleType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
unit
:(
HKUnit
*
)
unit
predicate
:(
NSPredicate
*
)
predicate
predicate
:(
NSPredicate
*
)
predicate
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
f51978cc
...
@@ -9,6 +9,9 @@
...
@@ -9,6 +9,9 @@
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Utils.h"
#import "RCTAppleHealthKit+Utils.h"
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
@implementation
RCTAppleHealthKit
(
Queries
)
@implementation
RCTAppleHealthKit
(
Queries
)
...
@@ -199,7 +202,65 @@
...
@@ -199,7 +202,65 @@
[
self
.
healthStore
executeQuery
:
query
];
[
self
.
healthStore
executeQuery
:
query
];
}
}
-
(
void
)
setObserverForType
:(
HKSampleType
*
)
type
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
{
NSLog
(
@"set observer"
);
void
(
^
handler
)(
HKObserverQuery
*
query
,
HKObserverQueryCompletionHandler
completionHandler
,
NSError
*
_Nullable
error
);
handler
=
^
(
HKObserverQuery
*
query
,
HKObserverQueryCompletionHandler
completionHandler
,
NSError
*
_Nullable
error
)
{
NSLog
(
@"enter to a handler %@"
,
[
error
localizedDescription
]);
UIApplication
*
app
=
[
UIApplication
sharedApplication
];
UIApplicationState
appState
=
[
app
applicationState
];
if
(
!
self
.
isSync
){
// switch (appState) {
// case UIApplicationStateActive:
// NSLog(@"app Active try to make sync");
// break;
// case UIApplicationStateInactive:
// {
// NSLog(@"enter to inactive case");
// break;
// }
// case UIApplicationStateBackground:
// {
// NSLog(@"enter to background case");
// self.isSync = true;
// __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [app beginBackgroundTaskWithExpirationHandler:^{
//
// NSLog(@"call event background");
//// [self.bridge.eventDispatcher sendAppEventWithName:@"change:steps"
//// body:@{@"name": @"change:steps"}];
// [self fetchSamplesOfType:type unit:unit predicate:nil ascending:true limit:1 completion:completion];
// [app endBackgroundTask:backgroundTaskIdentifier];
// self.isSync = false;
// }];
// }
//
// };
NSLog
(
@"enter to background case"
);
self
.
isSync
=
true
;
__block
UIBackgroundTaskIdentifier
backgroundTaskIdentifier
=
[
app
beginBackgroundTaskWithExpirationHandler
:
^
{
NSLog
(
@"call event background"
);
[
self
.
bridge
.
eventDispatcher
sendAppEventWithName
:
@"change:steps"
body:
@{
@"name"
:
@"change:steps"
}];
[
self
fetchSamplesOfType
:
type
unit
:
unit
predicate
:
nil
ascending
:
true
limit
:
1
completion
:
completion
];
[
app
endBackgroundTask
:
backgroundTaskIdentifier
];
completionHandler
();
self
.
isSync
=
false
;
}];
}
};
HKObserverQuery
*
query
=
[[
HKObserverQuery
alloc
]
initWithSampleType
:
type
predicate
:
nil
updateHandler
:
handler
];
[
self
.
healthStore
executeQuery
:
query
];
[
self
.
healthStore
enableBackgroundDeliveryForType
:
type
frequency
:
HKUpdateFrequencyImmediate
withCompletion
:^
(
BOOL
success
,
NSError
*
_Nullable
error
)
{
NSLog
(
@"success %s print some error %@"
,
success
?
"true"
:
"false"
,
[
error
localizedDescription
]);
}];
}
...
...
RCTAppleHealthKit/RCTAppleHealthKit.h
View file @
f51978cc
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
@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
;
...
...
RCTAppleHealthKit/RCTAppleHealthKit.m
View file @
f51978cc
...
@@ -111,6 +111,12 @@ RCT_EXPORT_METHOD(getSamples:(NSDictionary *)input callback:(RCTResponseSenderBl
...
@@ -111,6 +111,12 @@ RCT_EXPORT_METHOD(getSamples:(NSDictionary *)input callback:(RCTResponseSenderBl
[
self
fitness_getSamples
:
input
callback
:
callback
];
[
self
fitness_getSamples
:
input
callback
:
callback
];
}
}
RCT_EXPORT_METHOD
(
setObserver
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
[
self
fitness_setObserver
:
input
callback
:
callback
];
}
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
];
...
...
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