gpt4 book ai didi

ios - 在 web View 中拦截加载的 javascript 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:03:41 27 4
gpt4 key购买 nike

我正在使用 WKWebView 制作网页 View 应用

let url = NSURL(string: "http://www.example.com")
let request = NSURLRequest(url: url! as URL)
homeWebView.load(request as URLRequest)

But I want to intercept some javaScript file of this website before it loads to change functionality and make the app a bit native looking

如有任何帮助,我们将不胜感激。

谢谢。

最佳答案

以下是完整的示例。希望对您有所帮助。

import UIKit

class ViewController: UIViewController,UIWebViewDelegate {

private var webView: UIWebView!

override func loadView() {
webView = UIWebView(frame: .zero)
webView.delegate = self
view = webView
}

override func viewDidLoad() {
super.viewDidLoad()
// set the view controller title, navigation etc
self.loadWebPage()
}

func loadWebPage() {
let url = URL(string: "https://www.google.com.pk/")
// let localFileURL = URL(fileURLWithPath: Bundle.main.path(forResource: "ExampleHtmlFileName", ofType: "html", inDirectory: "HtmlFilesFolderName")!)
let myRequest = URLRequest(url: url!)
webView.loadRequest(myRequest)
}

//MARK: UIWebView Delegate
func webViewDidFinishLoad(_ webView: UIWebView) {

let jsScript = "exampleJSMethod()"
_ = webView.stringByEvaluatingJavaScript(from: jsScript)
}


}

关于ios - 在 web View 中拦截加载的 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49686478/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com