Commit e3725593 authored by Evgenii Evstropov's avatar Evgenii Evstropov

fix background workouts observer

parent 2178a8ed
......@@ -208,23 +208,20 @@
- (void)setObserverForType:(HKSampleType *)type
unit:(HKUnit *)unit {
NSLog(@"set observer");
HKObserverQuery *query = [[HKObserverQuery alloc] initWithSampleType:type predicate:nil updateHandler:^(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError * _Nullable error){
UIApplication *app = [UIApplication sharedApplication];
NSLog(@"observer fired");
if (error) {
NSLog(@"*** An error occured while setting up the stepCount observer. %@ ***", error.localizedDescription);
return;
}
[self.bridge.eventDispatcher sendAppEventWithName:@"observer" body:@""];
completionHandler();
// self.isSync = true;
// __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [app beginBackgroundTaskWithExpirationHandler:^{
//
// NSLog(@"observer fired from bg");
// [self.bridge.eventDispatcher sendAppEventWithName:@"observer"
// body:@""];
//
// [app endBackgroundTask:backgroundTaskIdentifier];
// Theoretically, HealthKit expect that copletionHandler would be called at the end of query process,
// but it's unclear how to do in in event paradigm
// dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 5);
// dispatch_after(delay, dispatch_get_main_queue(), ^(void){
// completionHandler();
// self.isSync = false;
// }];
// });
}];
[self.healthStore executeQuery:query];
......
......@@ -22,6 +22,7 @@
#import <React/RCTEventDispatcher.h>
@implementation RCTAppleHealthKit
@synthesize bridge = _bridge;
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