Reputation: 337
How can i detect the running IOS version using cocos2d-x?
When i used cocos2d i used the code below but i don't wanna go 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)
Maybe it is possible to use UIDevice with cocos2d-x, i don't know.
Upvotes: 2
Views: 1621
Reputation: 1745
The way I implemented in cocos2d-x 3.4, is to add the following method in CCApplication-ios.mm
float Application::getSystemVersion() {
return [[UIDevice currentDevice].systemVersion floatValue];
}
Add this to CCApplication-ios.h
/** Get iOS version */
static float getSystemVersion();
And call it anywhere by using
float systemVersion = Application::getSystemVersion();
Upvotes: 1
Reputation: 827
try your code in appcontroller.mm class. it will work.
already cocos2d-x is checking the version like this for setting 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];
}
Upvotes: 1