Using JavaScript function calls
P粉118698740
2023-08-15 17:25:19
<p>I want to call a JS function from Swift</p>
<p>I want to get the result of JS in Swift. I have a lot of functions that need to be called from Swift. These functions may or may not contain parameters. You also need to include a closure for the result. </p>
Call the function like this:
func setCompleteAdInJavaScript() { let javascriptFunction = """ gameState.setCredits('200'); """ webView.evaluateJavaScript(javascriptFunction) { result, error in if let _ = error { print("设置积分出错") } else { print("成功设置积分。") } } }