I have a project that must upload data in background and keep data going even when the app is closed/terminated. In very rare cases I have encountered the problem that when background uploading is in process (app was fully closed/terminated) and when I open the application a white (blank) screen appears. No splash screen, no content in webview, but I still can see my logs that the background tasks is producing. After the completion of data uploading the white screen does not go away, obviously.
My application is built React on gets loaded in a WebView. I noticed one thing, although I see only a white screen, according to the inspector the DOM is fully loaded and functional and the connection between React app and native app is still there (callbacks, facades). Reloading page or opening another page doesn't have any positive effect. Also I am able to highlight elements using Safari's inspector and can visually observe their outlines on the end device. They're present, but content doesn't renders at all.
The problem lies precisely because of the incorrect operation of WebKit when the application goes into the foreground during background tasks active, after when the user swipes away the application and the system terminates the application (app termination is an important condition).
To solve this problem I used the following:
- An attempt to catch the system closing Webkit and then reload React App. I implemented this method
func webViewWebContentProcessDidTerminate(_ webView: WKWebView) However I never get into this method (unless I destroy the process associated with webkit in the emulator myself). Obviously process doesn't gets terminated and it's not the cause. 2. Trying to resize the WebView doesn't solve the problem either. 3. I tried to do webView.reload() after the application gets into willEnterForeground, but this does not always work correctly and does not completely solve the problem. Sometimes the webView is rendered, and sometimes there is still a white screen even though the method was called. 4. I tried calling webView.loadHTMLString on a "broken" webview just to make sure that React app is not the cause and it still doesn't render anything, yet i can see the new content from inspector but white screen still stay. 5. Complete recreation of WKWebView (removing the old one from WebViewContainer, creating and adding the new one, loading react app) is solving the problem, but it is a pretty much rough workaround, similiar to app restarting. And also I find it difficult to find a right moment/event to apply this workaround.
Are there any known related issues or any known causes of this? What can be putting webview into this weird state?