app中获取应用名称,版本等信息的方法

在app中,我们有时候需要显示一些信息,例如名称,版本等等。。。
如果用写死的方式可能不太好,我们可以动态的读取。
应用的信息主要是在info.plist这个文件中,实际就是一个xml文件,以源文件的方式打开,可以看到。

读取的实例代码如下:

    
NSDictionary* dict = [[NSBundle mainBundle] infoDictionary]; // 这个字典的获取很关键
NSLog(@"APP VERSION:%@", [dict objectForKey:(__bridge NSString *)kCFBundleVersionKey]);
NSLog(@"APP INFO DIC VER:%@", [dict objectForKey:(__bridge NSString *)kCFBundleInfoDictionaryVersionKey]);
NSLog(@"APP EXECUTABLE:%@", [dict objectForKey:(__bridge NSString *)kCFBundleExecutableKey]);
NSLog(@"APP REGION:%@", [dict objectForKey:(__bridge NSString *)kCFBundleDevelopmentRegionKey]);
NSLog(@"APP NAME:%@", [dict objectForKey:(__bridge NSString *)kCFBundleNameKey]);

输出如下:

2013-09-22 22:03:08.832 infoReader[19736:c07] APP VERSION:1.0
2013-09-22 22:03:08.834 infoReader[19736:c07] APP INFO DIC VER:6.0
2013-09-22 22:03:08.834 infoReader[19736:c07] APP EXECUTABLE:infoReader
2013-09-22 22:03:08.835 infoReader[19736:c07] APP REGION:en
2013-09-22 22:03:08.835 infoReader[19736:c07] APP NAME:infoReader

app名称,版本等信息都读到了。。。有兴趣的朋友还可以继续拓展。

原文地址:https://www.cnblogs.com/yingkong1987/p/3334027.html