cocos2d-x版本号获取
ios
int CIosDeviceInfo::getGameVersion(char *version)
{
NSBundle * bundle = [NSBundle mainBundle];
if( nil == bundle )
{
return 0;
}
NSString* appVersion = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
//NSString* appBuild = [bundle objectForInfoDictionaryKey:@"CFBundleVersion"];
if( nil == appVersion )
{
return 0;
}
if( NULL != version )
{
const char * tmp =[appVersion UTF8String];
strcpy( version, tmp );
}
NSArray * components = [appVersion componentsSeparatedByString:@"."];
if( 0 == [components count] )
{
return 0;
}
int tmp = 0;
for( int i=0; i<[components count]; ++i )
{
int j = [components count] - 1 - i;
int k = pow(10,i);
tmp += [(NSString *)[components objectAtIndex:j] intValue] * k;
}
return tmp;
}
android
void ToolHelper::getAppVersionName(char * buf)
{
CCLOG("ToolHelper::getAppVersionName().start");
//定义Jni函数信息结构体
JniMethodInfo minfo;
bool isHave = JniHelper::getStaticMethodInfo(minfo, "com/yiwanzu/game/sgcard","getAppVersionName","()Ljava/lang/String;");
jstring jstr = NULL;
if (!isHave) {
CCLOG("jni function null");
}else{
CCLOG("jni function ok");
//调用Java中getUuid函数
jstr = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
char *versionName = (char *) minfo.env->GetStringUTFChars(jstr, 0);
CCLOG("versionName : %s", versionName);
strcpy(buf, versionName);
CCLOG("versionName : %s", versionName);
//minfo.env->DeleteLocalRef(jstr);
CCLOG("versionName : %s", versionName);
}
CCLOG("jni function loaded");
}