Using JavaScript function calls
P粉118698740
P粉118698740 2023-08-15 17:25:19
0
1
557
<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>
P粉118698740
P粉118698740

reply all(1)
P粉493534105

Call the function like this:

func setCompleteAdInJavaScript() {
    let javascriptFunction = """
    gameState.setCredits('200');
    """
    
    webView.evaluateJavaScript(javascriptFunction) { result, error in
        
        if let _ = error {
            print("设置积分出错")
            
        } else {
            print("成功设置积分。")
            
        }
        
    }
    
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template