NSBundle
来源:互联网 发布:nginx 访问报404 编辑:程序博客网 时间:2024/06/05 00:46
1.获取app的info.plist详细信息
版本号:Bundle version
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
应用标识:Bundle identifier
NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
应用名称:Bundle display name
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
Bundle name
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
2.应用程序语言本地化
app本地化宏
#define XLocalizedString(key, comment) [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
中英文两个Localizable.strings文件中键值对,例如
"none" = "确定";
"none" = "none";
宏的用法:(返回NSString *)
localizedString("none", "这是注释")
3.获取包内文件路径和文件
获取app包路径
NSString *path = [[NSBundle mainBundle] bundlePath];
app资源目录路径
NSString *resPath = [[NSBundle mainBundle] resourcePath];
获取资源目录下a.bundle
NSString* path = [resPath stringByAppendingPathComponent:@"a.bundle"];NSBundle *bundle = [NSBundle bundleWithPath:path];
获取app包的readme.txt文件路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"readme" ofType:@"txt"];
NSLog(@"ios 应用发布后 .app 应用文件 路径::%@",[NSBundle mainBundle] );
NSLog(@"ios 应用发布后 .app 应用包(文件) 的详细信息 ::%@",[[NSBundle mainBundle] infoDictionary]);
[[NSBundle mainBundle] infoDictionary] 返回的是一个数据字典内容如下:
(XX1 为当前应用的名字 也就是app 包的名字 )--( 部分地方 XX 大写 我隐藏了部分信息...... )
ios 应用发布后 .app 应用文件内 ::{
CFBundleDevelopmentRegion = en;
CFBundleDisplayName = "当前app 文件名XX1";
CFBundleExecutable = "当前app 文件名XX1";
CFBundleExecutablePath = "/Users/yq-010/Library/Application Support/iPhone Simulator/5.1/Applications/49419CEE-6608-48FE-81FE-BF40FEEFB8F7/XX1.app/xx1";
CFBundleIconFiles = (
"icon.png",
"icon@2x.png"
);
CFBundleIcons = {
CFBundlePrimaryIcon = {
CFBundleIconFiles = (
"icon.png",
"icon@2x.png"
);
UIPrerenderedIcon = 1;
};
};
CFBundleIdentifier = "com.xxxx.xxxxx";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleInfoPlistURL = "Info.plist -- file://localhost/Users/yq-010/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/49419CEE-6608-48FE-81FE-BF40FEEFB8F7/XX%20XX%20XX.app/";
CFBundleName = "XX1";
CFBundlePackageType = APPL;
CFBundleShortVersionString = "1.3";
CFBundleSignature = "????";
CFBundleSupportedPlatforms = (
iPhoneSimulator
);
CFBundleVersion = "1.3";
DTPlatformName = iphonesimulator;
DTSDKName = "iphonesimulator5.1";
LSRequiresIPhoneOS = 1;
NSBundleInitialPath = "/Users/yq-010/Library/Application Support/iPhone Simulator/5.1/Applications/49419CEE-6608-48FE-81FE-BF40FEEFB8F7/XX1.app";
NSBundleResolvedPath = "/Users/yq-010/Library/Application Support/iPhone Simulator/5.1/Applications/49419CEE-6608-48FE-81FE-BF40FEEFB8F7/XX1.app";
UIDeviceFamily = (
1
);
UIPrerenderedIcon = 1;
UIRequiredDeviceCapabilities = (
armv7
);
UISupportedInterfaceOrientations = (
UIInterfaceOrientationPortrait
);
}
应用1:我们可以通过包的信息的数据字典 得到 应用的版本 CFBundleVersion = "1.3";
当前应用的版本 :
[[[NSBundlemainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]]
- nsbundle
- nsbundle
- NSBundle
- NSBundle
- nsbundle
- NSBundle
- NSBundle
- NSBundle
- NSBundle
- NSBundle
- NSBundle
- NSBundle
- NSBundle
- NSBundle
- nsbundle
- NSBundle
- NSBundle
- NSbundle
- Junit初探
- 几种建模工具简介(SPSS,SAS,Stata,R,Matlab,Amos,Lisrel)
- Eratosthenes筛法 素数筛
- Slab分配机制
- 使用STM32的RTC制作万年历
- NSBundle
- 20150202 N1
- android 布局分类及属性
- CSS Border使用小分享
- 保留小数点的四种方法
- 关于ota升级查找不到更新包的原因分析
- C++中const成员函数和非const成员函数的重载
- IOS7 UITableView一行滑动删除后 被删除行的下一行的点击事件将被忽略解决办法
- OsgEarth 字体及一些的参数特征应用