Миграция определенного метода из UIWebView в WKWebView - PullRequest
0 голосов
/ 01 ноября 2018

Я видел несколько общих вопросов о перемещении UIWebView в WKWebView, вот так и это .

У меня есть конкретный случай использования навигации по карте изображений. Первый метод является независимым от класса и легко конвертируемым. Я понимаю метод эквивалентный в WKWebView, но я не вижу, как это помогает мне.

Я использую код (ниже), и он прекрасно работает, но я бы хотел быть в курсе событий и перейти на WKWebKit, если это возможно.

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
    }
...