call a swift function from js

You need to change your Javascript (or inject Javascript code) to call postMessage() function instead. Since you can only pass one parameter you can compose a JSON:{
    "orderId": orderId,
    "status": "ACCEPTED"

That way you can handle body property of WKScriptMessage like a dictionary, in Swift:

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
    let dictionary = message.body as? [String: Any]
        let orderId = dictionary?["orderId"] as? Int,
        let email = dictionary?["email"] as? String,
        let status = dictionary?["status"] as? String
    else { return }
    delegate?.preScreenerFinished(orderId, email, status)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top