美文网首页codeER.teciOS学习笔记2017-3-29
iOS代码实现获得项目名称及版本号(Version/Build)

iOS代码实现获得项目名称及版本号(Version/Build)

作者: RyderZhang | 来源:发表于2016-07-06 13:52 被阅读6727次

app名称:

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];

获取系统版本:

NSString * systemVersion = [UIDevice currentDevice].systemVersion;//10.0.2
CGFloat test = [[UIDevice currentDevice] systemVersion].floatValue;//10

iOS代码实现获得项目名称及版本号(Version/Build):

NSString *executableFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey];//获取项目名称
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];//获取项目版本号
iOS的版本号,一个叫做Version,一个叫做Build,这两个值都可以在Xcode中选中target,点击"General"后看到。 Version在plist文件中的key是“CFBundleShortVersionString”,和AppStore上的版本号保持一致。
Build在plist中的key是“CFBundleVersion”,代表build的版本号,该值每次build之后都应该增加1。

//获得应用的Verison号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
或
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

//获得build号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
01target.png 02Info.plist.png

相关文章

网友评论

  • 曾经像素有点低:把获取线上版本号的也加上吧(比如我手机上的是旧版本,获取apstore现在是什么版本)
  • 藕藕藕汀:Bundle version和Bundle versions string,short是什么区别
    RyderZhang:前者是Build,后者是Version

本文标题:iOS代码实现获得项目名称及版本号(Version/Build)

本文链接:https://www.haomeiwen.com/subject/lrpfjttx.html