WKWebView goes blank after memory warning

前端 未结 1 1367
长发绾君心
长发绾君心 2021-02-20 11:34

I\'m developing an iOS app that will show some 360 panoramic content in a wkWebView. The page does load, but when it receives a memory warning, it shows a blank view on iPad 2.

1条回答
  •  灰色年华
    2021-02-20 12:07

    One major cause of this is the WebContent process crashing.

    In iOS 9 and above you can use the WKNavigationDelegate method webViewWebContentProcessDidTerminate to catch this case. It's up to you to decide how to respond to the crash, but if reloading the page is enough, then [webView reload] will do the trick as shown below. As @ray mentions in the comments, you will not get any useful information about the why of the crash from this delegate call.

    - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
        // Reload current page, since we have crashed the WebContent process
        // (most likely due to memory pressure)
        [webView reload];
    }
    

    In iOS8 and below, you can check if myWKWebViewInstance.title is nil.

    0 讨论(0)
提交回复
热议问题