ios通过.mm文件进行调用AppController.mm的方法
js_bindings_lcm_api.h:
// // js_bindings_lcm_api.h // MoonWarriors // // Created by xiaohei on 2/21/17. // // #ifndef __LCM__js_bindings_lcm_api__ #define __LCM__js_bindings_lcm_api__ #include "cocos2d.h" namespace LCMJSB { class LCMAPI : public cocos2d::Ref { public: static LCMAPI* getInstance(); private: LCMAPI(); virtual ~LCMAPI(); public: void continueProcessing(); void LUpdateBalance(); void checkBalanceEnoughForPay(std::string sku,std::string transid); void setLExtraData(std::string eventName,std::string jsonData); std::string getLAccessToken(); std::string getLUserStringInfo(); std::string getLIdFromUser(); std::string getLTotalBalance(); std::string getLPaidBalance(); std::string getLFreeBalance(); std::string getChannelName(); bool getLIsShowBalance(); void setLMenuBarVisible(bool isShow,int pos); void showLCustomerService(); void lcmlogout(); void lcmLogin(); void lcmNotifyClean(); void lcmNotifyEveryday(int hour,int min,std::string title,std::string txt,std::string icon,int code); private: // static LCMAPI * instance_; }; } #endif /* defined(__LCM__js_bindings_lcm_api__) */
js_bindings_lcm_api.mm:
// // js_bindings_lcm_api.cpp // MoonWarriors // // Created by xiaohei on 3/2/17. // // #include "js_bindings_lcm_api.h" #import "Reachability.h" #import "AppController.h" #import <UIKit/UIKit.h> using namespace cocos2d; namespace LCMJSB { //LCMAPI* LCMAPI::instance_ = nullptr; LCMAPI* LCMAPI::getInstance() { static LCMAPI instance_; return std::addressof(instance_); } LCMAPI::LCMAPI() { } LCMAPI::~LCMAPI() { } void LCMAPI::continueProcessing() { [AppController continueProcessing]; } std::string LCMAPI::getLTotalBalance() { std::string *ret = new std::string([[AppController getLTotalBalance] UTF8String]); return *ret; } bool LCMAPI::getLIsShowBalance() { bool ret = (bool)[AppController getLIsShowBalance]; return ret; } void LCMAPI::lcmNotifyEveryday(int hour,int code) { NSString *nstitle= [NSString stringWithCString:title.c_str() encoding:NSUTF8StringEncoding]; NSString *nstxt= [NSString stringWithCString:txt.c_str() encoding:NSUTF8StringEncoding]; NSString *nsicon= [NSString stringWithCString:icon.c_str() encoding:NSUTF8StringEncoding]; [AppController lcmNotifyEveryday:hour withMin:min withTitle:nstitle withTxt:nstxt withIcon:nsicon withCode:code]; } }原文链接:https://www.f2er.com/cocos2dx/339265.html