原文地址:http://blog.csdn.net/shx_yi/article/details/8755415?
1辐董、使用類方法創(chuàng)建一個NSBundler對象
+ (NSBundle *)mainBundle;
eg:[NSBundle mainBundle];
2放闺、使用路徑獲取一個NSBundle 對象,這個路徑應該是一個目錄的全路徑
+ (NSBundle *)bundleWithPath:(NSString *)path;
eg:
NSString *path = [mailBundle resourcePath];
NSBundle *language = [NSBundlebundleWithPath:path];
3三圆、使用路徑初始化一個NSBundle
- (id)initWithPath:(NSString *)path;
4骂租、使用一個url 創(chuàng)建并初始化一個NSBundle對象(這是一個類方法)
注:這里的url 是一個特殊的 文件url路徑
+ (NSBundle *)bundleWithURL:(NSURL *)url
5蚊夫、使用一個url 初始化一個NSBundle對象
注:這里的url 是一個特殊的 文件url路徑
- (id)initWithURL:(NSURL *)url
6券时、根據(jù)一個特殊的class 獲取NSBundle
+ (NSBundle *)bundleForClass:(Class)aClass;
eg:根據(jù)當前的class 獲取一個NSBundle // 獲取當前類的NSBundle
NSBundle *bud = [NSBundle bundleForClass:[self class]];
NSLog(@"bud==%@",bud);
輸出結果如下:
NSBundle
7邮旷、獲取特定名稱的bundle
+ (NSBundle *)bundleWithIdentifier:(NSString *)identifier;
8黄选、使用NSBundle 獲取所有的bundle信息(由于ios安全沙盒的限制,所有的獲取的資源婶肩,是應用程序的資源)
注:官方標注办陷,獲取所有的非framework 的bundle;
+ (NSArray *)allBundles;
eg:
NSArray *array = [NSBundle allBundles];
NSLog(@"array===%@",array);
打印的結果如下:
array===(
"NSBundle (loaded)"
)
9、獲取應用程序加載的所有framework的資源律歼,
+ (NSArray *)allFrameworks;
eg:
NSArray *array = [NSBundle allFrameworks];
NSLog(@"%@",array);
輸出的結果如下:(
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)",
"NSBundle (loaded)"
)
10民镜、判斷bundle 加載,(按照官方文檔,You don’t need to load a bundle’s executablecode to search the bundle’s resources.我們不需要調(diào)用這個方法,)
- (BOOL)load;
11险毁、判斷bundle 加載
- (BOOL)isLoaded;
12制圈、判斷bundle 加載
- (BOOL)unload;
13、加載資源畔况,如果有錯誤的話鲸鹦,會放置錯誤信息
- (BOOL)preflightAndReturnError:(NSError **)error
- (BOOL)loadAndReturnError:(NSError **)error
14、獲取bundle 類實例的 url
- (NSURL *)bundleURL
15跷跪、獲取bundle 類實例的 resourceUrl 資源
- (NSURL *)resourceURL
16馋嗜、獲取bundle 類實例的 可執(zhí)行的URL
- (NSURL *)executableURL
17、(Returns the file URL of the executable with the specified namein the receiver’s bundle.返回一個,文件的URL吵瞻,使用一個特殊的名稱)
- (NSURL *)URLForAuxiliaryExecutable:(NSString*)executableName
18葛菇、獲取當前NSBundle實例的 URL 資源
- (NSURL *)privateFrameworksURL
19甘磨、獲取共享的frameworkdURL
- (NSURL *)sharedFrameworksURL
20、 獲取支持的Bundle的Url
- (NSURL *)sharedSupportURL
21眯停、獲取添加插件的URL
- (NSURL *)builtInPlugInsURL
// 已經(jīng)不能使用宽档,
- (NSURL *)appStoreReceiptURL
22、 獲取bundle 的path 路徑
- (NSString *)bundlePath;
23庵朝、獲取bundle 的資源路徑字符串
- (NSString *)resourcePath;
24、獲取bundle 可執(zhí)行文件路徑
- (NSString *)executablePath;
25又厉、獲取bundle 輔助的path
- (NSString *)pathForAuxiliaryExecutable:(NSString*)executableName;
26九府、獲取私有的路徑框架
- (NSString *)privateFrameworksPath;
27、獲取共享的framework path 路徑
- (NSString *)sharedFrameworksPath;
28覆致、獲取共享的路徑
- (NSString *)sharedSupportPath;
29侄旬、獲取插件的路徑
- (NSString *)builtInPlugInsPath;
// 已經(jīng)廢棄,不能調(diào)用
+ (NSURL *)URLForResource:(NSString *)name withExtension:(NSString*)ext subdirectory:(NSString *)subpath inBundleWithURL:(NSURL*)bundleURL
// 已經(jīng)廢棄
+ (NSArray *)URLsForResourcesWithExtension:(NSString *)extsubdirectory:(NSString *)subpath inBundleWithURL:(NSURL*)bundleURL
30煌妈、使用bundle 創(chuàng)建一個資源文件的URL
- (NSURL *)URLForResource:(NSString *)name withExtension:(NSString*)ext
eg:
NSURL* URL=[[NSBundle mainBundle] URLForResource:fileNamewithExtension:@"png"];
31儡羔、(官方描述如下:Returns the file URL for the resource file identified bythe specified name and extension and residing in a given bundledirectory.
使用資源文件的名稱以及擴展名,還有子路徑)
- (NSURL *)URLForResource:(NSString *)name withExtension:(NSString*)ext subdirectory:(NSString *)subpath
32璧诵、(官方描述:
Returns the file URL for the resource identified by the specifiedname and file extension,
located in the specified bundle subdirectory, and limited to globalresources and those associated with the specifiedlocalization.)
同上一個方法汰蜘,不同的是添加了本地資源文件的信息
- (NSURL *)URLForResource:(NSString *)name withExtension:(NSString*)ext subdirectory:(NSString *)subpath localization:(NSString*)localizationName
33、根據(jù)文件的后綴名稱和子目錄之宿,獲取一個NSURL 的數(shù)組
- (NSArray *)URLsForResourcesWithExtension:(NSString *)extsubdirectory:(NSString *)subpath
34族操、同上面的方法,添加了本地化的一個資源文件
- (NSArray *)URLsForResourcesWithExtension:(NSString *)extsubdirectory:(NSString *)subpath localization:(NSString*)localizationName
35比被、根據(jù)資源文件的名稱色难,或者是文件的后綴名稱以及目錄的路徑,獲取 path
+ (NSString *)pathForResource:(NSString *)name ofType:(NSString*)ext inDirectory:(NSString *)bundlePath;
36等缀、根據(jù)文件的擴展名枷莉,以及資源的路徑,獲取一個數(shù)組
+ (NSArray *)pathsForResourcesOfType:(NSString *)extinDirectory:(NSString *)bundlePath;
37尺迂、根據(jù)文件的名稱和擴展名獲取 path 名稱
- (NSString *)pathForResource:(NSString *)name ofType:(NSString*)ext;
37笤妙、根據(jù)文件的名稱和擴展名獲取 path 名稱
- (NSString *)pathForResource:(NSString *)name ofType:(NSString*)ext inDirectory:(NSString *)subpath;
37、根據(jù)文件的名稱和擴展名獲取 path 名稱
- (NSString *)pathForResource:(NSString *)name ofType:(NSString*)ext inDirectory:(NSString *)subpath forLocalization:(NSString*)localizationName;
38噪裕、根據(jù)文件的擴展名和子目錄獲取一個資源文件的數(shù)組
- (NSArray *)pathsForResourcesOfType:(NSString *)extinDirectory:(NSString *)subpath;
39危喉、同上,添加了資源文件的一個路徑
- (NSArray *)pathsForResourcesOfType:(NSString *)extinDirectory:(NSString *)subpath forLocalization:(NSString*)localizationName;
40州疾、方法調(diào)用解釋如下
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString*)value table:(NSString *)tableName NS_FORMAT_ARGUMENT(1);
你可以通過NSBundle來找到對應key值的vaule.
NSBundle *main = [NSBundle mainBundle];
NSString *aString = [main localizedStringForKey:@"Key1"
value:@"DefaultValue1"
table:@"Find"];
上面的代碼會在Find.strings中查找"Key1"對應的 vuale字符串.如果沒有提供用戶指定的語言的本地化資源,那么就會查找第二個所選語言,如果第二個也沒有本地化資源,就依次找下去.如果到最后還是沒有找到,那么 ""DefaultValue1"將會返回
// 返回當前bundle的唯一標示:(即:應用的唯一標示)
- (NSString *)bundleIdentifier;
eg:com.company.ios-Example-NSBundle.IOS-Example-NSBundle
// 獲取資源文件的dictionary 對象
- (NSDictionary *)infoDictionary;
eg:
{
CFBundleDevelopmentRegion =en;
CFBundleDisplayName ="IOS_Example_NSBundle";
CFBundleExecutable ="IOS_Example_NSBundle";
CFBundleExecutablePath ="/Users/ctrip1/Library/Application Support/iPhoneSimulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app/IOS_Example_NSBundle";
CFBundleIdentifier ="com.company.ios-Example-NSBundle.IOS-Example-NSBundle";
CFBundleInfoDictionaryVersion= "6.0";
CFBundleInfoPlistURL ="Info.plist -- file://localhost/Users/ctrip1/Library/ApplicationSupport/iPhoneSimulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app/";
CFBundleName ="IOS_Example_NSBundle";
CFBundlePackageType =APPL;
CFBundleShortVersionString ="1.0";
CFBundleSignature ="????";
CFBundleSupportedPlatforms =? ? (
iPhoneSimulator
);
CFBundleVersion = "1.0";
DTPlatformName =iphonesimulator;
DTSDKName ="iphonesimulator6.1";
LSRequiresIPhoneOS = 1;
NSBundleInitialPath ="/Users/ctrip1/Library/Application Support/iPhoneSimulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app";
NSBundleResolvedPath ="/Users/ctrip1/Library/Application Support/iPhoneSimulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app";
UIDeviceFamily =? ? (
1,
2
);
UIRequiredDeviceCapabilities =? ? (
armv7
);
UISupportedInterfaceOrientations =? ? (
UIInterfaceOrientationPortrait,
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight
);
}
41辜限、返回本地化資源的NSDictionary 對象
- (NSDictionary *)localizedInfoDictionary;
42、根據(jù)key 值獲取本地化資源對象的值
- (id)objectForInfoDictionaryKey:(NSString *)key;
43严蓖、(官方描述:Returns the Class object for the specifiedname.根據(jù)類名字符串獲取一個類對象)
- (Class)classNamed:(NSString *)className;
44薄嫡、返回主要的類
- (Class)principalClass;
45氧急、返回本地化資源的列表
- (NSArray *)localizations;
46、本地化的語言列表
- (NSArray *)preferredLocalizations;
47毫深、使用創(chuàng)建的類獲取本地化語言
- (NSString *)developmentLocalization;
48吩坝、(官方描述 Returns one or more localizations from the specified listthat a bundle object would use to locate resources for the currentuser.)
+ (NSArray *)preferredLocalizationsFromArray:(NSArray*)localizationsArray;
+ (NSArray *)preferredLocalizationsFromArray:(NSArray*)localizationsArray forPreferences:(NSArray *)preferencesArray;