Commit e3725593 authored by Evgenii Evstropov's avatar Evgenii Evstropov

fix background workouts observer

parent 2178a8ed
...@@ -208,23 +208,20 @@ ...@@ -208,23 +208,20 @@
- (void)setObserverForType:(HKSampleType *)type - (void)setObserverForType:(HKSampleType *)type
unit:(HKUnit *)unit { unit:(HKUnit *)unit {
NSLog(@"set observer");
HKObserverQuery *query = [[HKObserverQuery alloc] initWithSampleType:type predicate:nil updateHandler:^(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError * _Nullable error){ HKObserverQuery *query = [[HKObserverQuery alloc] initWithSampleType:type predicate:nil updateHandler:^(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError * _Nullable error){
UIApplication *app = [UIApplication sharedApplication]; if (error) {
NSLog(@"observer fired"); NSLog(@"*** An error occured while setting up the stepCount observer. %@ ***", error.localizedDescription);
[self.bridge.eventDispatcher sendAppEventWithName:@"observer" body:@""]; return;
completionHandler(); }
// self.isSync = true; [self.bridge.eventDispatcher sendAppEventWithName:@"observer" body:@""];
// __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [app beginBackgroundTaskWithExpirationHandler:^{
// // Theoretically, HealthKit expect that copletionHandler would be called at the end of query process,
// NSLog(@"observer fired from bg"); // but it's unclear how to do in in event paradigm
// [self.bridge.eventDispatcher sendAppEventWithName:@"observer"
// body:@""]; // dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 5);
// // dispatch_after(delay, dispatch_get_main_queue(), ^(void){
// [app endBackgroundTask:backgroundTaskIdentifier];
// completionHandler(); // completionHandler();
// self.isSync = false; // });
// }];
}]; }];
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment