OC和Cocos-js的互相调用
Posted 小师傅啊小师傅
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OC和Cocos-js的互相调用相关的知识,希望对你有一定的参考价值。
OC调用cocos-js
#import "ScriptingCore.h" #import "cocos2d.h" #include "scripting/js-bindings/manual/ScriptingCore.h" #include "scripting/js-bindings/manual/jsb_conversions.hpp" #include "scripting/js-bindings/jswrapper/SeApi.h" #define JSCallBackHasVoice @"cc.director.getScene().getChildByName(‘Canvas‘).getComponent(‘OCRecorder‘).hasVoice"
//hasVoice是cocos-js的方法
+ (void)JsCallBack:(NSString *)funcNameStr WithIndex:(NSInteger)index{ std::string funcName = [funcNameStr UTF8String]; NSString *numberStr = [NSString stringWithFormat:@"%ld",index]; std::string coins = [numberStr UTF8String]; std::string jsCallStr = cocos2d::StringUtils::format("%s("%s");",funcName.c_str(), coins.c_str()); se::ScriptEngine::getInstance()->evalString(jsCallStr.c_str()); }
以上是关于OC和Cocos-js的互相调用的主要内容,如果未能解决你的问题,请参考以下文章
iOS下JS与OC互相调用--WKWebView 拦截URL