cocos / cocos-docs

Manual docs content for Cocos Creator
https://docs.cocos.com
307 stars 461 forks source link

如何在 iOS 平台上使用 Javascript 直接调用 Objective-C 方法 #2178

Closed DemonH21 closed 1 year ago

DemonH21 commented 2 years ago

URL : https://github.com/cocos-creator/creator-docs/blob/master/zh/advanced-topics/oc-reflection.md

Application::getInstance()->getScheduler()->performFunctionInCocosThread([=](){ se::ScriptEngine::getInstance()->evalString(script.c_str()); }); :memo: https://github.com/cocos-creator/creator-docs/blob/master/zh/advanced-topics/oc-reflection.md#L71

有没有完整事例2.4版本

MrKylinGithub commented 1 year ago

下面这个代码,是用于 OC/C++ 调用 JS 的。(由于这段是C++代码,如果要在OC中调用,OC文件要用 .mm 后缀,就可以实现 C++ 和 OC 混编)

Application::getInstance()->getScheduler()->performFunctionInCocosThread([=](https://github.com/cocos/cocos-docs/issues/2178){
se::ScriptEngine::getInstance()->evalString(script.c_str());
});

JS 调用 OC 请参考:https://docs.cocos.com/creator/2.4/manual/zh/advanced-topics/oc-reflection.html