Disable magnification gesture in WKWebView

You can prevent your users from zooming by setting the delegate of your WKWebKit’s UIScrollView and implementing viewForZooming(in:) as in the following: class MyClass { let webView = WKWebView() init() { super.init() webView.scrollView.delegate = self } deinit() { // Without this, it’ll crash when your MyClass instance is deinit’d webView.scrollView.delegate = nil } } extension … Read more

Using custom fonts in WKWebView

I faced same issue, in my case i could fix it WITHOUT using base64 encoding and GCDWebServer. Scenario: WkWebView loading is through string html WkWebView is using local .css Fonts are local and are added at top level project Entries for fonts are provided in appName-info.plist under key UIAppFonts / Fonts provided by application (Note: … Read more

Get HTML from WKWebview in Swift

If you wait until the page has loaded you can use: webView.evaluateJavaScript(“document.documentElement.outerHTML.toString()”, completionHandler: { (html: Any?, error: Error?) in print(html) }) You could also inject some javascript that returns you back the HTML. let script = WKUserScript(source: javascriptString, injectionTime: injectionTime, forMainFrameOnly: true) userContentController.addUserScript(script) self.webView.configuration.userContentController.addScriptMessageHandler(self, name: “didGetHTML”) … func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) { if … Read more

The font looks like smaller in WKWebView than in UIWebView

Finally I solved this problem by adding an html string: For Objective-C: NSString *headerString = @”<head><meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no”></head>”; [self.webView loadHTMLString:[headerString stringByAppendingString:yourHTMLString] baseURL:nil]; For Swift: let headerString = “<head><meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no”></head>” webView.loadHTMLString(headerString + yourHTMLString, baseURL: nil) What’s more,if you want to load url rather than html you can … Read more

How to remove cache in WKWebView?

Updated Swift 5 version: WKWebsiteDataStore.default().removeData(ofTypes: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache], modifiedSince: Date(timeIntervalSince1970: 0), completionHandler:{ }) Swift version: if #available(iOS 9.0, *) { let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache]) let date = NSDate(timeIntervalSince1970: 0) WKWebsiteDataStore.defaultDataStore().removeDataOfTypes(websiteDataTypes as! Set<String>, modifiedSince: date, completionHandler:{ }) } else { var libraryPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, false).first! libraryPath += “/Cookies” do { try NSFileManager.defaultManager().removeItemAtPath(libraryPath) } catch … Read more

WKWebView open links from certain domain in safari

You can implement WKNavigationDelegate, add the decidePolicyForNavigationAction method and check there the navigationType and requested url. I have used google.com below but you can just change it to your domain: Xcode 8.3 • Swift 3.1 or later import UIKit import WebKit class ViewController: UIViewController, WKNavigationDelegate { let webView = WKWebView() override func viewDidLoad() { super.viewDidLoad() … Read more

How to Migrate to WKWebView?

UIWebView will still continue to work with existing apps. WKWebView is available starting from iOS8, only WKWebView has a Nitro JavaScript engine. To take advantage of this faster JavaScript engine in older apps you have to make code changes to use WKWebView instead of UIWebView. For iOS7 and older, you have to continue to use … Read more

iOS 13 – WkWebView: audio stops when in background

I guess you are using Capacitor. I’m running into the same issue as you and it looks like the last error about ‘no background task exists’ has something to do with Capacitor’s BackgroundTask Plugin, wether you’re using it or not (BackgroundTask.swift) It’s clear something changed between iOS 12 and iOS 13, but so far haven’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)