diff --git a/src/ios/WebAppLocalServer.swift b/src/ios/WebAppLocalServer.swift index e6a811f..00751e5 100644 --- a/src/ios/WebAppLocalServer.swift +++ b/src/ios/WebAppLocalServer.swift @@ -112,10 +112,12 @@ open class WebAppLocalServer: METPlugin, AssetBundleManagerDelegate { self?.revertToLastKnownGoodVersion() } } + + NotificationCenter.default.addObserver(self, selector: #selector(WebAppLocalServer.pageDidLoad), name: NSNotification.Name.CDVPageDidLoad, object: webView) NotificationCenter.default.addObserver(self, selector: #selector(WebAppLocalServer.applicationDidEnterBackground), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil) - - NotificationCenter.default.addObserver(self, selector: #selector(WebAppLocalServer.pageDidLoad), name: NSNotification.Name.CDVPageDidLoad, object: webView) + + NotificationCenter.default.addObserver(self, selector: #selector(WebAppLocalServer.applicationWillEnterForeground), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil) } func initializeAssetBundles() { @@ -194,7 +196,10 @@ open class WebAppLocalServer: METPlugin, AssetBundleManagerDelegate { self.pendingAssetBundle = nil } - startupTimer?.start(withTimeInterval: startupTimeoutInterval) + // Don't start the startup timer if the app started up in the background + if UIApplication.shared.applicationState == UIApplicationState.active { + startupTimer?.start(withTimeInterval: startupTimeoutInterval) + } } // MARK: - Notifications @@ -207,6 +212,11 @@ open class WebAppLocalServer: METPlugin, AssetBundleManagerDelegate { // blacklisting a version just because the web view has been suspended startupTimer?.stop() } + + func applicationWillEnterForeground() { + // Restart startup timer when entering the foreground again + startupTimer?.start(withTimeInterval: startupTimeoutInterval) + } // MARK: - Public plugin commands