diff --git a/React/CoreModules/RCTTiming.mm b/React/CoreModules/RCTTiming.mm index 1c6e61047f8320..f47bcbd432309b 100644 --- a/React/CoreModules/RCTTiming.mm +++ b/React/CoreModules/RCTTiming.mm @@ -105,7 +105,6 @@ @implementation RCTTiming NSTimer *_sleepTimer; BOOL _sendIdleEvents; BOOL _inBackground; - UIBackgroundTaskIdentifier _backgroundTaskIdentifier; id _timingDelegate; } @@ -136,7 +135,6 @@ - (void)setup _paused = YES; _timers = [NSMutableDictionary new]; _inBackground = NO; - _backgroundTaskIdentifier = UIBackgroundTaskInvalid; for (NSString *name in @[UIApplicationWillResignActiveNotification, UIApplicationDidEnterBackgroundNotification, @@ -158,35 +156,10 @@ - (void)setup - (void)dealloc { - [self markEndOfBackgroundTaskIfNeeded]; [_sleepTimer invalidate]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } -- (void)markStartOfBackgroundTaskIfNeeded -{ - if (_backgroundTaskIdentifier == UIBackgroundTaskInvalid) { - __weak RCTTiming *weakSelf = self; - // Marks the beginning of a new long-running background task. We can run the timer in the background. - _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"rct.timing.gb.task" expirationHandler:^{ - RCTTiming *strongSelf = weakSelf; - if (!strongSelf) { - return; - } - // Mark the end of background task - [strongSelf markEndOfBackgroundTaskIfNeeded]; - }]; - } -} - -- (void)markEndOfBackgroundTaskIfNeeded -{ - if (_backgroundTaskIdentifier != UIBackgroundTaskInvalid) { - [[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier]; - _backgroundTaskIdentifier = UIBackgroundTaskInvalid; - } -} - - (dispatch_queue_t)methodQueue { return RCTJSThread; @@ -212,7 +185,6 @@ - (void)appDidMoveToBackground - (void)appDidMoveToForeground { - [self markEndOfBackgroundTaskIfNeeded]; _inBackground = NO; [self startTimers]; } @@ -313,7 +285,6 @@ - (void)didUpdateFrame:(RCTFrameUpdate *)update } if (_inBackground) { if (timerCount) { - [self markStartOfBackgroundTaskIfNeeded]; [self scheduleSleepTimer:nextScheduledTarget]; } } else if (!_sendIdleEvents && timersToCall.count == 0) { @@ -416,7 +387,6 @@ - (void)createTimerForNextFrame:(nonnull NSNumber *)callbackID } if (_inBackground) { - [self markStartOfBackgroundTaskIfNeeded]; [self scheduleSleepTimer:timer.target]; } else if (_paused) { if ([timer.target timeIntervalSinceNow] > kMinimumSleepInterval) {