首页 > 解决方案 > 如何在 WKWebView 中使用动态查询字符串打开 url

问题描述

我的网站上有一个按钮,它有 href https://live.example.net/?dynamic_encypted_query-string,所以我想在我的 ios 应用程序的 webview 中打开这个 url。目前我正在通过电容器框架构建一个 Web 应用程序,在该框架中我将代码写入我的 WebViewController.swift 文件

    class WebViewController: UIViewController, WKUIDelegate {

    var webView: WKWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let url = URL(string: "https://live.example.net/?*")
        let myRequest = URLRequest(url: url!)
        webView.load(myRequest)

        // Do any additional setup after loading the view.
    }
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }
}

这会在 Web 视图中打开域(https://live.example.net),但我想用查询字符串数据打开它。

let url = URL(string: "https://live.example.net/?*")

我认为这也不适用于获取查询字符串数据。

标签: iosswiftweb-applications

解决方案


推荐阅读