1

I've seen a number of general questions about moving UIWebView to WKWebView, like this and this.

I have a specific usage case navigating through an imageMap. The first method is class agnostic, and easy to convert. I understand the method equivalent in WKWebView, but I cannot see how this helps me.

I'm using the code (below) and this works nicely, but I'd like to keep up to date and migrate to WKWebKit if this is possible,.

func makeImageMap() {

        var imagePath = Bundle.main.resourcePath
        imagePath = imagePath?.replacingOccurrences(of: "/", with: "//")
        imagePath = imagePath?.replacingOccurrences(of: " ", with: "%20")

        let filePath = Bundle.main.path(forResource: "metro-2015", ofType: "html")
        let htmlData = NSData(contentsOfFile: filePath ?? "") as Data?
        if let aData = htmlData, let aPath = URL(string: "file:/\(imagePath ?? "")//") {
            webView.load(aData, mimeType: "text/html", textEncodingName: "UTF-8", baseURL: aPath)
        }
    }


    func webView(_ aWebView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {


        let url: URL? = request.url
        let stationCode = url?.fragment
        if stationCode != nil && (stationCode?.count ?? 0) > 0 {

            for i in 0..<stations.count {
                let station = stations[i]

                codeString = station.code
                if (codeString == stationCode) {
                    print(#function, "MATCH", station.name!)
                    showActionSheet()
                }
            }

        }

        return true
    }
ICL1901
  • 7,632
  • 14
  • 90
  • 138

0 Answers0