iOS 代碼實現獲得應用的版本號(Version/Build)

jopen 10年前發布 | 391K 次閱讀 IOS iOS開發 移動開發

[1]概念

iOS的版本號,一個叫做Version,一個叫做Build,這兩個值都可以在Xcode 中選中target,點擊“Summary”后看到。 Version在plist文件中的key是“CFBundleShortVersionString”,和AppStore上的版本號保持一致,Build在plist中的key是“CFBundleVersion”,代表build的版本號,該值每次build之后都應該增加1。這兩個值都可以在程序中通過下面的代碼獲得:

[[[NSBundle mainBundle] infoDictionary] valueForKey:@"key"]

[2]具體實現

代碼實現獲得應用的Verison號:

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

獲得build號:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

轉載鏈接:

[1]http://joeyio.com/ios/2013/05/25/xcode-version-management/

[2]http://stackoverflow.com/questions/7957794/how-to-get-your-own-app-version-from-xcode

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!