How to prevent WKWebView from closing when starting the Cordova plugin

I am using the cordova-plugin-wkwebview-engine plugin to run my html5 application in Cordoba. Due to the architecture of WKWebView, the web view is loaded into another stream. Now, when I open another stream from Cordoba (EG, taking an image using the camera plug-in), and iOS gives a warning about saving memory when the camera is active, the web view is killed.

Apparently, the WKWebView view is being processed as a background thread and stopped. Now, when the camera returns, the application is blank (white screen) because web browsing no longer exists. In UIWebView (which we abandoned due to better performance in WKWebView) we worked on the main thread of the application and therefore were never killed.

Is there a way to prevent WKWebView from closing? If the application cannot support the main application working with WKWebView, it would be useless for anything other than displaying overlays on a web page.

+5
source share
1 answer

It seems that there are quite a few memory management WKWebView for WKWebView , as well as some iOS 9 security changes that may be useful to solve your problem.

HERE is an argument in support of Apple explaining why your WKWebView is returning empty, and not just your application crashing:

While it is possible that the WKWebView process may exceed your memory budget, this will not cause your application to terminate or lead to a simple presentation.

In addition, this question sheds light on the NSAppTransportSecurity Protocol (iOS 9 changes), which also cause a similar problem. Although this is not memory related, it might be worth a peek if you are using an insecure URL in an instance of WKWebView.

If you use the HTTP URL during any request, you need to include:

 <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict> 

in your .plist application.

If you still cannot solve the problem, I would recommend checking the chrome forum for WKWebView, along with a possible lowering of the quality parameter for the camera plug-in to reduce the memory problem.

+3
source

Source: https://habr.com/ru/post/1238944/


All Articles