mirror of
https://github.com/blanking003/cx-cocos.git
synced 2025-11-04 21:35:33 +00:00
init
This commit is contained in:
23
cx-framework3.1/cx-native/cxSys/cxSysIntf.h
Normal file
23
cx-framework3.1/cx-native/cxSys/cxSysIntf.h
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cxDefine.h"
|
||||
#include "cocos/bindings/event/EventDispatcher.h"
|
||||
|
||||
class CxSysIntf : public NativeIntfClass
|
||||
{
|
||||
public:
|
||||
static CxSysIntf* ins();
|
||||
|
||||
virtual std::string call(std::string fname, cc::ValueVector params, const DataCallback& callback) override;
|
||||
|
||||
static DataCallback m_cxSysCallback;
|
||||
|
||||
private:
|
||||
|
||||
void restartForUpdate(cc::CustomEvent evt);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
70
cx-framework3.1/cx-native/cxSys/cxSysIntf.mm
Normal file
70
cx-framework3.1/cx-native/cxSys/cxSysIntf.mm
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
#include "cxSysIntf.h"
|
||||
|
||||
#include "AppController.h"
|
||||
#include "platform/Application.h"
|
||||
#include "cocos/bindings/event/CustomEventTypes.h"
|
||||
|
||||
DataCallback CxSysIntf::m_cxSysCallback = NULL;
|
||||
|
||||
static CxSysIntf* s_sharedCxSysIntf = nullptr;
|
||||
CxSysIntf* CxSysIntf::ins()
|
||||
{
|
||||
if (!s_sharedCxSysIntf)
|
||||
s_sharedCxSysIntf = new CxSysIntf();
|
||||
return s_sharedCxSysIntf;
|
||||
}
|
||||
|
||||
std::string CxSysIntf::call(std::string fname, cc::ValueVector params, const DataCallback& callback)
|
||||
{
|
||||
if (fname == "getStoragePath")
|
||||
{
|
||||
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
return "";
|
||||
#endif
|
||||
return call("getPackageName", params, callback);
|
||||
}
|
||||
|
||||
if (fname == "getPackageName")
|
||||
{
|
||||
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
||||
NSString* packageName = [infoDictionary objectForKey:@"CFBundleIdentifier"];
|
||||
return [packageName UTF8String];
|
||||
}
|
||||
|
||||
if (fname == "getVersionCode")
|
||||
{
|
||||
return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] UTF8String];
|
||||
}
|
||||
|
||||
if (fname == "getVersionName")
|
||||
{
|
||||
return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] UTF8String];
|
||||
}
|
||||
|
||||
|
||||
if (fname == "removeLaunchImage")
|
||||
{
|
||||
[[AppController ins] removeLaunchImage];
|
||||
return "";
|
||||
}
|
||||
|
||||
//只供在main.js中,且是ios时调用这个方法
|
||||
if (fname == "restartForUpdate")
|
||||
{
|
||||
//ios弹出网络授权时,应用会进入后台,点击后回到前台,侦听回到前台时重启
|
||||
cc::EventDispatcher::addCustomEventListener(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(CxSysIntf::restartForUpdate, this));
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void CxSysIntf::restartForUpdate(cc::CustomEvent evt)
|
||||
{
|
||||
if (evt.name == EVENT_COME_TO_FOREGROUND)
|
||||
{
|
||||
cc::EventDispatcher::removeAllCustomEventListeners(EVENT_COME_TO_FOREGROUND);
|
||||
cc::Application::getInstance()->restart();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user