diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index 355188589..d67c57b3d 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -642,10 +642,6 @@ - (void)savePendingUpdate:(NSString *)packageHash // a resume-based update still pending installation. - (void)applicationWillEnterForeground { - if (_appSuspendTimer) { - [_appSuspendTimer invalidate]; - _appSuspendTimer = nil; - } // Determine how long the app was in the background and ensure // that it meets the minimum duration amount of time. int durationInBackground = 0; @@ -653,8 +649,18 @@ - (void)applicationWillEnterForeground durationInBackground = [[NSDate date] timeIntervalSinceDate:_lastResignedDate]; } - if (durationInBackground >= _minimumBackgroundDuration) { - [self loadBundle]; + if (_installMode == CodePushInstallModeOnNextSuspend) { + // We shouldn't use loadBundle in this case, because _appSuspendTimer will call loadBundleOnTick. + // We should cancel timer for _appSuspendTimer because otherwise, we would call loadBundle two times. + if (durationInBackground < _minimumBackgroundDuration) { + [_appSuspendTimer invalidate]; + _appSuspendTimer = nil; + } + } else { + // For resume install mode. + if (durationInBackground >= _minimumBackgroundDuration) { + [self loadBundle]; + } } }