JavascriptCore是iOS7支持的新框架.我们可以使用JSExport协议将部分objc类暴露给JavaScript.
在javascript中,我试图将函数作为参数传递.像这样:
function getJsonCallback(json) {
movie = JSON.parse(json)
renderTemplate()
}
viewController.getJsonWithURLCallback("", getJsonCallback)
Run Code Online (Sandbox Code Playgroud)
在我的objc viewController中,我定义了我的协议:
@protocol FetchJsonForJS <JSExport>
- (void)getJsonWithURL:(NSString *)URL
callback:(void (^)(NSString *json))callback;
- (void)getJsonWithURL:(NSString *)URL
callbackScript:(NSString *)script;
@end
Run Code Online (Sandbox Code Playgroud)
在javascript中,viewController.getJsonWithURLCallbackScript可以工作,但是,viewController.getJsonWithURLCallback不起作用.
我在JSExport中使用了块有什么错误吗?谢谢.