【发布时间】:2014-03-24 10:45:44
【问题描述】:
JavascriptCore 是 iOS7 支持的新框架。我们可以使用 JSExport 协议将部分 objc 类暴露给 JavaScript。
在 javascript 中,我尝试将函数作为参数传递。就像这样:
function getJsonCallback(json) {
movie = JSON.parse(json)
renderTemplate()
}
viewController.getJsonWithURLCallback("", getJsonCallback)
在我的 objc viewController 中,我定义了我的协议:
@protocol FetchJsonForJS <JSExport>
- (void)getJsonWithURL:(NSString *)URL
callback:(void (^)(NSString *json))callback;
- (void)getJsonWithURL:(NSString *)URL
callbackScript:(NSString *)script;
@end
在 javascript 中,viewController.getJsonWithURLCallbackScript 有效,但是 viewController.getJsonWithURLCallback 无效。
我在 JSExport 中使用 block 有什么错误吗?谢谢。
【问题讨论】:
标签: javascript ios hybrid-mobile-app javascriptcore