1、获取info.plist信息
版本号:Bundle version
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
应用标识:Bundle identifier
NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
应用名称(手机显示名称):Bundle display name
NSString *appDisName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
应用名称(.api显示名称,建议不修改):Bundle name
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
2、应用程序语言本地化
app本地化宏定义(Localizable.strings默认文件)
#define NSLocalizedString(key, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
#define NSLocalizedStringFromTable(key, tbl, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
[bundle localizedStringForKey:(key) value:@"" table:(tbl)]
#define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment) \
[bundle localizedStringForKey:(key) value:(val) table:(tbl)]
键值设置(例如:中英文两个Localizable.strings文件中键值)
//英语Localizable.strings(English)文件
"你好" = "hello";
//简体中文Localizable.strings(Simplified)文件
"你好" = "你好";
宏的使用:(返回NSString *)
//comment为注释,可传可不传不影响返回
NSLocalizedString(@"你好", nil)
//other表示查询other.strings文件
NSLocalizedStringFromTable(@"你好", @"other", nil)
推荐大神(秋刀生鱼片)的教程:iOS 本地化入门教程 - 简书
3、获取包内文件路径和文件
获取app包路径
NSString *path = [[NSBundle mainBundle] bundlePath];
app资源目录路径
NSString *resPath = [[NSBundle mainBundle] resourcePath];
获取资源目录下Main.bundle
NSString* path = [resPath stringByAppendingPathComponent:@"Main.bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
获取app包的wordbook.txt文件路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"wordbook" ofType:@"txt"];
网友评论