Questions related to loading Swift WKWebView page.

Asked 2 years ago, Updated 2 years ago, 71 views

I'm making a hybrid app using WKWebView. There's a problem When you load a page in webview, you can't load it properly if you put # after url.

func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void)

I think I need to do this method, but I can't do this and that, and I don't know what to do. Help me

swift ios webview

2022-09-21 18:41

1 Answers

Creating a project with Single view application and configuring View Controller as shown in the code below, # works fine.

I changed the back of url in urlWithSharp to one, two, three, and so on.

import UIKit
import WebKit

class ViewController: UIViewController,WKNavigationDelegate {

    var webView : WKWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        let urlWithSharp = "http://www.owlcarousel.owlgraphic.com/demos/urlhashnav.html#three"
        let url = NSURL(string: urlWithSharp)
        let request = NSURLRequest(URL: url!)

        // // init and load request in webview.
        webView = WKWebView(frame: self.view.frame)
        webView.navigationDelegate = self
        webView.loadRequest(request)
        self.view.addSubview(webView)
        self.view.sendSubviewToBack(webView)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // // Dispose of any resources that can be recreated.
    }
}


2022-09-21 18:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.