使用Cocos2d-X检测IOS版本

使用Cocos2d-X检测IOS版本,cocos2d-x,Cocos2d X,如何使用cocos2d-x检测正在运行的IOS版本 当我使用cocos2d时,我使用了下面的代码,但我不想使用obj-c++ #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) #define SYSTEM_VERSION_GREATER_THAN(v)

如何使用cocos2d-x检测正在运行的IOS版本

当我使用cocos2d时,我使用了下面的代码,但我不想使用obj-c++

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

也许可以将UIDevice与cocos2d-x一起使用,我不知道。

在appcontroller.mm类中尝试您的代码。它会起作用的

cocos2d-x已经在检查像这样的版本以设置viewcontroller

// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
    // warning: addSubView doesn't work on iOS6
    [window addSubview: viewController.view];
}
else
{
    // use this method on ios6
    [window setRootViewController:viewController];
}
//将RootViewController设置为Windows
如果([[UIDevice currentDevice].systemVersion floatValue]<6.0)
{
//警告:addSubView在iOS6上不工作
[窗口添加子视图:viewController.view];
}
其他的
{
//在ios6上使用此方法
[窗口设置RootViewController:viewController];
}

我在cocos2d-x 3.4中实现的方法是在CCApplication-ios.mm中添加以下方法

float Application::getSystemVersion() {
    return [[UIDevice currentDevice].systemVersion floatValue];
}
将此添加到CCApplication ios.h

/** Get iOS version */
static float getSystemVersion();
并使用

float systemVersion = Application::getSystemVersion();

为什么不签入Objective-C?这是最自然的方式,Cocos2d-x在调用
AppDelegate
之前使用Objective-C启动你的应用程序。这不是Objective-C++,而是Objective-C。为什么会出现这个问题?您是否尝试过使用这些定义之一?它们工作正常,这是检查版本的正确方法。