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
f4fb1a9c
Commit
f4fb1a9c
authored
Feb 09, 2018
by
Adam Ivancza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Slight updates for HealthKit observer
parent
f51978cc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
61 deletions
+21
-61
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
+1
-1
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
+2
-4
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
+1
-2
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
+15
-52
RCTAppleHealthKit/RCTAppleHealthKit.m
RCTAppleHealthKit/RCTAppleHealthKit.m
+2
-2
No files found.
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.h
View file @
f4fb1a9c
...
...
@@ -12,7 +12,7 @@
-
(
void
)
fitness_getStepCountOnDay
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_getSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
;
-
(
void
)
fitness_getDailyStepSamples
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_saveSteps
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
-
(
void
)
fitness_initializeStepEventObserver
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
;
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Methods_Fitness.m
View file @
f4fb1a9c
...
...
@@ -91,7 +91,7 @@
}];
}
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
callback
:(
RCTResponseSenderBlock
)
callback
-
(
void
)
fitness_setObserver
:(
NSDictionary
*
)
input
{
HKUnit
*
unit
=
[
RCTAppleHealthKit
hkUnitFromOptions
:
input
key
:
@"unit"
withDefault
:
[
HKUnit
countUnit
]];
NSString
*
type
=
[
RCTAppleHealthKit
stringFromOptions
:
input
key
:
@"type"
withDefault
:
@"Walking"
];
...
...
@@ -111,9 +111,7 @@
samplesType
=
[
HKObjectType
workoutType
];
}
[
self
setObserverForType
:
samplesType
unit
:
unit
completion
:^
(
NSArray
*
results
,
NSError
*
error
)
{
callback
(@[[
NSNull
null
],
results
]);
}];
[
self
setObserverForType
:
samplesType
unit
:
unit
];
}
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.h
View file @
f4fb1a9c
...
...
@@ -27,8 +27,7 @@
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
-
(
void
)
setObserverForType
:(
HKSampleType
*
)
quantityType
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
;
unit
:(
HKUnit
*
)
unit
;
-
(
void
)
fetchQuantitySamplesOfType
:(
HKQuantityType
*
)
quantityType
...
...
RCTAppleHealthKit/RCTAppleHealthKit+Queries.m
View file @
f4fb1a9c
...
...
@@ -14,7 +14,6 @@
@implementation
RCTAppleHealthKit
(
Queries
)
-
(
void
)
fetchMostRecentQuantitySampleOfType
:(
HKQuantityType
*
)
quantityType
predicate
:(
NSPredicate
*
)
predicate
completion
:(
void
(
^
)(
HKQuantity
*
,
NSDate
*
,
NSDate
*
,
NSError
*
))
completion
{
...
...
@@ -203,58 +202,25 @@
}
-
(
void
)
setObserverForType
:(
HKSampleType
*
)
type
unit
:(
HKUnit
*
)
unit
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
{
unit
:(
HKUnit
*
)
unit
{
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
]);
HKObserverQuery
*
query
=
[[
HKObserverQuery
alloc
]
initWithSampleType
:
type
predicate
:
nil
updateHandler
:^
(
HKObserverQuery
*
query
,
HKObserverQueryCompletionHandler
completionHandler
,
NSError
*
_Nullable
error
){
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");
NSLog
(
@"observer fired"
);
[
self
.
bridge
.
eventDispatcher
sendAppEventWithName
:
@"observer"
body
:
@""
];
completionHandler
();
// 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];
//
NSLog(@"observer fired from bg
");
//
[self.bridge.eventDispatcher sendAppEventWithName:@"observer
"
//
body:@""
];
//
// [app endBackgroundTask:backgroundTaskIdentifier];
// completionHandler();
// 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
)
{
...
...
@@ -262,9 +228,6 @@
}];
}
-
(
void
)
fetchSleepCategorySamplesForPredicate
:(
NSPredicate
*
)
predicate
limit
:(
NSUInteger
)
lim
completion
:(
void
(
^
)(
NSArray
*
,
NSError
*
))
completion
{
...
...
RCTAppleHealthKit/RCTAppleHealthKit.m
View file @
f4fb1a9c
...
...
@@ -111,9 +111,9 @@ RCT_EXPORT_METHOD(getSamples:(NSDictionary *)input callback:(RCTResponseSenderBl
[
self
fitness_getSamples
:
input
callback
:
callback
];
}
RCT_EXPORT_METHOD
(
setObserver
:
(
NSDictionary
*
)
input
callback
:
(
RCTResponseSenderBlock
)
callback
)
RCT_EXPORT_METHOD
(
setObserver
:
(
NSDictionary
*
)
input
)
{
[
self
fitness_setObserver
:
input
callback
:
callback
];
[
self
fitness_setObserver
:
input
];
}
...
...
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