1.此兩個檔案依定要透過Xcode 開啟!檔案總館看不倒
位於專案中的cocos2d/build/cocosd_libs.xcodeproj/ platform/ios/CCApplication-ios.h
class CC_DLL Application : public ApplicationProtocol 增加
const char *getAppVersion();
const char *getBuild();
2.
cocos2d/build/cocosd_libs.xcodeproj/ platform/ios/CCApplication-ios.mm
//取得IOS 版本
float Application::getSystemVersion() {
return [[UIDevice currentDevice].systemVersion floatValue];
}
const char* Application::getAppVersion()
{
return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] UTF8String];
}
const char* Application::getBuild()
{
return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] UTF8String];
}
3. 使用 class/AppDelegate.cpp
printf("ios Vsersion=%1.1f\n",getSystemVersion());
printf("Appversin = %s.%s\n",getAppVersion(),getBuild());
參考文獻
====================================================================
Q:在coco2d中可以直接使用:
(AppController *)[[UIApplication sharedApplication] delegate]; 這樣的方法
但是在cocos2d-x中,這樣就不行了,有什麼理法可以得到AppController
也就是說怎麼樣c++的代碼和本地Object-c相互調用
A:
將文件後綴名修改為mm,進行混編
=========================================
以下OC 跟SWIFT 尚未找到呼叫範例
switf 範例
extension UIApplication {
class func appVersion() -> String {
return NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
}
class func appBuild() -> String {
return NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey as String) as! String
}
class func versionBuild() -> String {
let version = appVersion(), build = appBuild()
return version == build ? "v\(version)" : "v\(version)(\(build))"
}
}
========================================
Object CC 範例
@implementation UIApplication (AppVersion)
+ (NSString *) appVersion
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
}
+ (NSString *) build
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
}
+ (NSString *) versionBuild
{
NSString * version = [self appVersion];
NSString * build = [self build];
NSString * versionBuild = [NSString stringWithFormat: @"v%@", version];
if (![version isEqualToString: build]) {
versionBuild = [NSString stringWithFormat: @"%@(%@)", versionBuild, build];
}
return versionBuild;
}
@end
==============================================
取得ios 版本範例
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();
- string CCDevice::getVersionName()
- {
- return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] UTF8String];
- }
- NSString *developmentVersionNumber = [bundle objectForInfoDictionaryKey:@"CFBundleVersion"];
CFBundleVersion,標識(發佈或未發佈)的內部版本號。這是一個單調增加的字符串,包括一個或多個時期分隔的整數。
CFBundleShortVersionStri版本號的管理是一個謹慎的事情,希望各位開發者瞭解其中的意義。
比較小白,更新應用的時候遇到版本號CFBundleShortVersionStri
圖片裡的 Version 對應的就是CFBundleShortVersionStri ng (發佈版本號 如當前上架版本為1.1.0 之後你更新的時候可以改為1.1.1)
Build 對應的是 CFBundleVersion(內部標示,用以記錄開發版本的,每次更新的時候都需要比上一次高 如:當前版本是11 下一次就要大於11 比如 12,13 ....10000)
From:http://blog.sina.com.cn/s/blog_8c87ba3b0101a1gd.html
沒有留言:
張貼留言