美文网首页
iOS URL fragment(#), WKWebView l

iOS URL fragment(#), WKWebView l

作者: Ian_ | 来源:发表于2020-07-02 18:27 被阅读0次
  1. 使用 URL.init(string: "#about", relativeTo: indexURL)
if var indexURL = Bundle.main.url(forResource: "www", withExtension: nil) {
            indexURL.appendPathComponent("index.html")
            let url = URL.init(string: "#about", relativeTo: indexURL)!
            webView.load(URLRequest.init(url: url))
}
  1. 使用 URLComponents 来构建.
 if var indexURL = Bundle.main.url(forResource: "www", withExtension: nil) {
            indexURL.appendPathComponent("index.html")
            let com = URLComponents.init(string: "#/about")
            let url = com!.url(relativeTo: indexURL)!
            webView.load(URLRequest.init(url: url))
}

Referrence: URI_fragment

相关文章

网友评论

      本文标题:iOS URL fragment(#), WKWebView l

      本文链接:https://www.haomeiwen.com/subject/jvscfktx.html