1、oc调用cocos2d js
NSMutableString * nsmString = [NSMutableString string];
[nsmString appendString: @"g_WeiXinLogin("];
[nsmString appendFormat:@"\"%@\"",openid];
[nsmString appendFormat:@",\"%@\"",token];
[nsmString appendFormat:@",isbind];
[nsmString appendString: @")"];
NSString *funString = [NSString stringWithString:nsmString];
NSLog(@"===== funString:%@",funString);
const char * funchar = [funString UTF8String];
//oc调用js
ScriptingCore * sc = ScriptingCore::getInstance();
jsval outVal;
sc->evalString(funchar,&outVal);
2、cocos2d js 调用oc
var ret = jsb.reflection.callStaticMethod("NativeOcClass",
"callNativeUIWithTitle:andContent:",
"cocos2d-js",
"Yes! you call a Native UI from Reflection");
3、cocos2d js 调用android
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Test","hello","(Ljava/lang/String;)V","this is a message from js");
4、android调用 cocos2d js
Cocos2dxJavascriptJavaBridge.evalString("g_SmsAutoWrite(\""+smsCode+"\")");
参考网站:官网http://www.cocos2dx.net/post/254
原文链接:https://www.f2er.com/cocos2dx/340645.html