javascript调用oc的方法

1.引入#import <JavaScriptCore/JavaScriptCore.h>

2.JSContext *jsContext = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

3.jsContext[@"test"] = ^() {

        NSArray *argumentsArr = [JSContext currentArguments];

        

        for (value *jsVal in argumentsArr) {

            NSLog(@"%@", value);

        }

        JSValue *this = [JSContext currentThis];

        NSLog(@"this: %@",this);

        

    };

4.html  <button onclick="test()"></button>

posted @ 2015-12-26 16:58  永远的H  阅读(360)  评论(0编辑  收藏  举报