1
我仍然在學習Swift
所以請裸露在我身邊。 :)注入JavaScript到UIWebView
我想注入本地JS文件到UIWebView
。我有它設置爲加載網站的桌面版本,但它似乎沒有工作。我找不到Swift 3
中的任何東西來做到這一點,並試圖將它拼湊在一起,但似乎我擊中了一堵磚牆。
這是我到目前爲止有:
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.register(defaults: ["UserAgent": "custom value"])
webView.loadRequest(URLRequest(url: URL(string: "https://www.myfitnesspal.com/account/login")!))
func webViewDidFinishLoad(webView: UIWebView) {
let jsPath = Bundle.main.path(forResource: "mfpketo.user", ofType: "js")
webView.stringByEvaluatingJavaScript(from: jsPath!)
print("test")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
謝謝你的任何及所有的幫助!