wendux / DSBridge-IOS

:earth_asia: A modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and native.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift中同步的没问题,异步的一直报Method is not invoked ,已经检查过版本,web的是^3.1.3,iOS的是3.0.2

DGLY opened this issue · comments

commented

iOS端
class AntzbJsBridgeabc: NSObject {

@objc func testSyn(args:Dictionary<String,Any>) -> String {
    let msg = args["msg"] as? String ?? ""
    return String(format:"%@[sync call:%@]", msg, "test")
}

@objc func testAsyn(arg:String, handler: (String, Bool)->Void) {
    handler(String(format:"%@[async call:%@]", arg, "test"), true)
}

}

webview.addJavascriptObject(AntzbJsBridgeabc(), namespace: "abc")

Web端

this.msg = dsbridge.call("abc.testSyn", {a:"aa",b:12,msg:"asasas"}) //没问题

dsBridge.call("abc.testAsyn",'sassas', function (name) {//有问题,报Method is not invoked的错
this.msg = name
alert(name)
})

commented

找到问题了?

:octocat: From gitme Android

commented

好像是我写错了,js那边我重新写了一下就好了....谢谢大哥

js那边怎么写才对啊,我也是这个问题,同步没错,异步报错这个