Capture redirect url in wkwebview in ios

Use this WKNavigationDelegate method public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) { if(navigationAction.navigationType == .other) { if let redirectedUrl = navigationAction.request.url { //do what you need with url //self.delegate?.openURL(url: redirectedUrl) } decisionHandler(.cancel) return } decisionHandler(.allow) } Hope this helps

Adding header view to WKWebView ScrollView

In webView Delegate method – (void)webViewDidFinishLoad:(UIWebView *)webView add the following codebase, mainWebViewObj.scrollView.contentInset = UIEdgeInsetsMake(headerView.frame.size.height,0.0,headerView.frame.size.height,0.0); mainWebViewObj.scrollView.backgroundColor = [UIColor whiteColor]; if(![headerView superview]) { [webView.scrollView addSubview:headerView]; [webView.scrollView bringSubviewToFront:headerView]; } [mainWebViewObj.scrollView setContentOffset: CGPointMake(0, -mainWebViewObj.scrollView.contentInset.top) animated:NO]; this worked perfect for me. Hope it solves your problem.

WKWebView evaluate JavaScript return value

Update: This is not working on iOS 12+ anymore. I solved this problem by waiting for result until result value is returned. I used NSRunLoop for waiting, but I’m not sure it’s best way or not… Here is the category extension source code that I’m using now: @interface WKWebView(SynchronousEvaluateJavaScript) – (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script; @end @implementation … Read more

WKWebView fails to load images and CSS using loadHTMLString(_, baseURL:)

Without taking a look at your actual project it’s difficult to give some hundreed percent sure advices. However: class ViewController: UIViewController { var webView = WKWebView() override func viewDidLoad() { super.viewDidLoad() webView.translatesAutoresizingMaskIntoConstraints = false let views = [ “webView” : webView ] view.addSubview(webView) var constraints = NSLayoutConstraint.constraintsWithVisualFormat(“H:|[webView]|”, options: [.AlignAllLeading, .AlignAllTrailing], metrics: nil, views: views) constraints.appendContentsOf(NSLayoutConstraint.constraintsWithVisualFormat(“V:|[webView]|”, … Read more

UIWebView delegate method shouldStartLoadWithRequest: equivalent in WKWebView?

I’ve been looking for a good explanation myself, but haven’t found one. I’ve used the following in my app and everything seems to work (Edit: updated based on ccoroom’s comment): UIWebViewDelegate – webView:shouldStartLoadWithRequest:navigationType: WKNavigationDelegate – webView:decidePolicyForNavigationAction:decisionHandler: Here’s the other UIWebViewDelegate methods: UIWebViewDelegate – webViewDidStartLoad: WKNavigationDelegate – webView:didCommitNavigation: UIWebViewDelegate – webViewDidFinishLoad: WKNavigationDelegate – webView:didFinishNavigation: UIWebViewDelegate – … Read more

Call JavaScript function from native code in WKWebView

(I filed a Radar for this shortly after asking the question here.) A new method was just added a few days ago (thanks jcesarmobile for pointing it out): Add -[WKWebView evaluateJavaScript:completionHandler:] http://trac.webkit.org/changeset/169765 The method is available in iOS 8 beta 3 and up. Here’s the new method signature: /* @abstract Evaluates the given JavaScript string. … Read more

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