swift – Configuring WKWebView in iOS app with similar settings because the WebView counterpart in Android app

0
3


My Android app incorporates a WebView that’s used for particular functions, so it needs to be totally configured.

I set all the next preferences within the exercise that includes the WebView:

    webView.setVerticalScrollBarEnabled(true);
    webView.setHorizontalScrollBarEnabled(true);
    webView.setScrollbarFadingEnabled(false);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.setKeepScreenOn(false);
    webView.getSettings().setUseWideViewPort(false);
    webView.getSettings().setLoadWithOverviewMode(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAllowFileAccess(false);
    webView.getSettings().setAllowFileAccessFromFileURLs(false);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setAllowContentAccess(false);
    webView.getSettings().setCacheMode(LOAD_DEFAULT);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setGeolocationEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
    webView.getSettings().setMixedContentMode(MIXED_CONTENT_NEVER_ALLOW);
    if (Construct.VERSION.SDK_INT >= Construct.VERSION_CODES.O) {
        webView.getSettings().setSafeBrowsingEnabled(true);
    }
    webView.getSettings().setSupportMultipleWindows(false);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setAllowUniversalAccessFromFileURLs(false);
    webView.getSettings().setSaveFormData(true);
    webView.getSettings().setLoadsImagesAutomatically(true);
    webView.getSettings().supportZoom();
    CookieManager cookieManager=CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.setAcceptThirdPartyCookies(webView,true);
    cookieManager.setAcceptFileSchemeCookies(false);

The above talked about Android app has an iOS counterpart that has to sport the very same options, even for the WebView.
I’m making an attempt to determine the best way to configure the WKWebView within the iOS app.

I’m coping with key-value pairs to be appropriately set, I see, but it surely’s very totally different from Android:

        webView!.configuration.preferences.isFraudulentWebsiteWarningEnabled=true
        
        webView!.configuration.preferences.javaScriptCanOpenWindowsAutomatically=false
        webView!.configuration.preferences.setValue(false, forKey: "allowFileAccessFromFileURLs")
        webView!.configuration.preferences.setValue(true, forKey: "textInteractionEnabled")
        webView!.configuration.preferences.setValue(true, forKey: "loadsImagesAutomatically")
       //.setValue(true, forKey: "webSecurityEnabled")
        webView!.configuration.setValue(false, forKey: "allowUniversalAccessFromFileURLs")
        //webView!.configuration.preferences.setValue(true, forKey: "cookieEnabled")
        webView!.configuration.setValue(true, forKey: "allowsInlineMediaPlayback")
        //webConfiguration.setValue(false, forKey: "requiresUserGestureForAudioPlayback")
        webView!.configuration.preferences.setValue(false, forKey: "javaScriptCanAccessClipboard")
        webView!.configuration.preferences.setValue(true, forKey: "safeBrowsingEnabled")
        //webConfiguration.setValue(false, forKey: "fileSystemAccessEnabled")
        //webConfiguration.setValue(true, forKey: "storageAPIEnabled")
        //webConfiguration.setValue(true, forKey: "notificationsEnabled")
        webView!.configuration.preferences.setValue(true, forKey: "javaScriptEnabled")

        //possibly others with webView!.configuration.websiteDataStore.httpCookieStore
       

How one can see some settings are like

webView!.configuration.preferences.javaScriptCanOpenWindowsAutomatically=false

different ones are like

webView!.configuration.preferences.setValue(false, forKey: "allowFileAccessFromFileURLs")

different ones are like

 webView!.configuration.setValue(false, forKey: "allowUniversalAccessFromFileURLs")

however many ones are simply not attainable in any of the talked about methods as a result of keys are usually not current, so a runtime error is issued no matter kind I put these settings directions (some traces are commented to not have the runtime error).

I learn additionally that for some preferences you to must take care of issues like:

webView!.configuration.websiteDataStore.httpCookieStore

or much more complicated capabilities to drive storing cookies, like this:

func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {

//particular directions right here
...
...

    }

The right way to discover all keys to correctly carry out the remaining settings? I discovered these keys right here:

https://chromium.googlesource.com/chromium/src/android_webview/glue/+/refs/heads/predominant/java/src/com/android/webview/chromium/ContentSettingsAdapter.java

I have no idea if that makes any sense.

The right way to totally configure the WKWebView?

LEAVE A REPLY

Please enter your comment!
Please enter your name here