关键点:
1.js调用objective-c函数时,只需要保证和oc中的函数名字一致,参数可有可无。
2.oc中的函数,通过 [JSContext currentArguments];来获取对应的参数数组。
上代码:
协议声明
@protocol JsBridgeExport
-(void)preview;//js脚本中调用该函数,并传递多个参数.例如:iosObject.preview(a,b,c)
@end
实现:
@interface JsBridge : NSObject
-(void)preview;
@end
@interface JsBridge()
@end
@implementation JsBridge
-(void)preview
{
id args = [JSContext currentArguments];//任意个参数都可以获取
NSLog(@" args = %@", args);
}
@end
参考链接:https://blog.csdn.net/baohanqing/article/details/51193006
网友评论