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.
1.97k stars 309 forks source link

当服务器返回为JSON字符串,且回掉方法为Void的时候,程序会闪退 #38

Closed seanLee closed 6 years ago

seanLee commented 6 years ago

JavascriptInterfaceObject调用的方法返回值为void,且服务器传参为Json字符串时会闪退.

修改test.html代码为如下

function callSyn() {
        alert(dsBridge.call("testSyn", "{\"url\":\"https://gslb.miaopai.com/stream/U8wK~SkowQqfbmyHNhFyDH0vy-KhqWvmdQMHLQ__.mp4?ssig=f3c7cac4c571591cc1b4c1da917a6ea2&time_stamp=1526013092137&cookie_id=c90730d82972cf7f169f2d7d246fc6a9&vend=1&os=2&partner=1&platform=2&cookie_id=c90730d82972cf7f169f2d7d246fc6a9&refer=miaopai&scid=U8wK%7ESkowQqfbmyHNhFyDH0vy-KhqWvmdQMHLQ__\"}"))
    }

修改JsApiTest.m代码如下

- (void) testSyn:(NSString *) msg
{
//    return [msg stringByAppendingString:@"[ syn call]"];
    NSLog(@"%@",@"call");
}
wendux commented 6 years ago

API签名是有要求的,不能返回void, 可以参考文档:

In order to be compatible with IOS , we make the following convention on Object-C API signature:

For synchronous API.

(id) handler:(id) msg