我已经包含了我的函数以及我调用它的方式确实在控制台中打印“注入”,但似乎注入了 javascript dosent 我已经在 safari 控制台和 chrome 控制台中测试了 js,它可以工作,但在 wkwebview 中可以工作
@IBAction func Register(_ sender: RoundButton) {
let RegistrationURL = URL(string: "https://www.baitme.com")
let newRegister = URLRequest(url: RegistrationURL!)
registrationwebview.load(newRegister)
DispatchQueue.main.asyncAfter(deadline: .now() + 2 ) {
print("inside js")
self.javascript()
}
}
func javascript(){
let config = WKWebViewConfiguration()
let userContentController = WKUserContentController()
config.userContentController = userContentController
guard let scriptPath = Bundle.main.path(forResource: "checkout", ofType: "js"),
let scriptSource = try? String(contentsOfFile: scriptPath) else { return }
let userScript = WKUserScript(source: scriptSource, injectionTime: .atDocumentStart, forMainFrameOnly: true)
print("injecting")
userContentController.addUserScript(userScript)
}