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.96k stars 305 forks source link

执行方法时野指针崩溃问题 #65

Closed Jeykit closed 5 years ago

Jeykit commented 5 years ago

ret=[JavascriptInterfaceObject performSelector:sel withObject:arg];.//这个方法会导致野指针崩溃问题 建议改成 void(action)(id,SEL,id) = (void()(id,SEL,id))objc_msgSend; action(JavascriptInterfaceObject,sel,arg);

Platycodon commented 5 years ago

之前的版本在真机测试下这里不崩溃,模拟器崩溃,但是最新xcode打的包必崩。

Platycodon commented 5 years ago

我调了一下,是由于- (void)nativeWeb:(NSDictionary *)data,而web端并无传参导致的。目前是这么调了下。 if (arg == nil) { arg = [NSNull null]; } SuppressPerformSelectorLeakWarning( ret=[JavascriptInterfaceObject performSelector:sel withObject:arg]; ); 具体我也没通篇阅读源代码所以我也不知道其实会造成啥后果,但是至少不崩溃了。

wendux commented 5 years ago

@Platycodon API签名不对就会导致Crash:

image

返回值类型不能是void

John-yuxin commented 5 years ago

我也遇到这个crash了。我的返回值是bool,我试了下其它类型UIimage居然没有crash

loveNoodles commented 2 years ago

找到原因了: 约定的方法需要有返回值!