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、獲取包內(nèi)文件路徑和文件
獲取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"];