1、使用类方法创建一个NSBundler对象
+ (NSBundle *)mainBundle;
eg:[NSBundle mailBundle];
2、使用路径获取一个NSBundle 对象,这个路径应该是一个目录的全路径
+ (NSBundle *)bundleWithPath:(NSString *)path;
eg:  
NSString *path = [mailBundle resourcePath];
  NSBundle *language = [NSBundle bundleWithPath:path];
3、使用路径初始化一个NSBundle
- (id)initWithPath:(NSString *)path;

4、使用一个url 创建并初始化一个NSBundle对象(这是一个类方法)
注:这里的url 是一个特殊的 文件url路径
+ (NSBundle *)bundleWithURL:(NSURL *)url
5、使用一个url 初始化一个NSBundle对象
注:这里的url 是一个特殊的 文件url路径
- (id)initWithURL:(NSURL *)url
6、根据一个特殊的class 获取NSBundle
+ (NSBundle *)bundleForClass:(Class)aClass;
eg:根据当前的class 获取一个NSBundle // 获取当前类的NSBundle
NSBundle *bud = [NSBundle bundleForClass:[self class]];
NSLog(@"bud==%@",bud);
输出结果如下:
NSBundle </Users/ctrip1/Library/Application Support/iPhone Simulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app>
7、获取特定名称的bundle
+ (NSBundle *)bundleWithIdentifier:(NSString *)identifier;
8、使用NSBundle 获取所有的bundle信息(由于ios安全沙盒的限制,所有的获取的资源,是应用程序的资源)
注:官方标注,获取所有的非framework 的bundle;
+ (NSArray *)allBundles;
eg:
NSArray *array = [NSBundle allBundles];
NSLog(@"array===%@",array);
打印的结果如下:
array===(
    "NSBundle </Users/ctrip1/Library/Application Support/iPhone Simulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app> (loaded)"
)
9、获取应用程序加载的所有framework的资源,
+ (NSArray *)allFrameworks;
eg:
NSArray *array = [NSBundle allFrameworks];
NSLog(@"%@",array);
输出的结果如下:(
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/XPCObjects.framework> (loaded)",
 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/ProofReader.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/CommonUtilities.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/PrintKit.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/MobileCoreServices.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/lib/system> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/DataMigration.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/FaceCoreLight.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/AppSupport.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/BackBoardServices.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/CoreImage.framework> (loaded)",
   "NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/MobileInstallation.framework> (loaded)",
)

10、判断bundle 加载,(按照官方文档,You don’t need to load a bundle’s executable code to search the bundle’s resources.我们不需要调用这个方法,)
- (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 类实例的 可执行的URL 
- (NSURL *)executableURL

17、(Returns the file URL of the executable with the specified name in 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
// 已经不能使用,
- (NSURL *)appStoreReceiptURL
22、 获取bundle 的path 路径
- (NSString *)bundlePath;

23、获取bundle 的资源路径字符串
- (NSString *)resourcePath;

24、获取bundle 可执行文件路径
- (NSString *)executablePath;

25、获取bundle 辅助的path
- (NSString *)pathForAuxiliaryExecutable:(NSString *)executableName;

26、获取私有的路径框架
- (NSString *)privateFrameworksPath;
27、获取共享的framework path 路径
- (NSString *)sharedFrameworksPath;

28、获取共享的路径
- (NSString *)sharedSupportPath;

29、获取插件的路径
- (NSString *)builtInPlugInsPath;

// 已经废弃,不能调用
+ (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)ext subdirectory:(NSString *)subpath inBundleWithURL:(NSURL *)bundleURL
// 已经废弃
+ (NSArray *)URLsForResourcesWithExtension:(NSString *)ext subdirectory:(NSString *)subpath inBundleWithURL:(NSURL *)bundleURL

30、使用bundle 创建一个资源文件的URL
- (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)ext
eg:
NSURL* URL=[[NSBundle mainBundle] URLForResource:fileName withExtension:@"png"];
31、(官方描述如下:Returns the file URL for the resource file identified by the specified name and extension and residing in a given bundle directory.
使用资源文件的名称以及扩展名,还有子路径)
- (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)ext subdirectory:(NSString *)subpath

32、(官方描述:
Returns the file URL for the resource identified by the specified name and file extension, 
located in the specified bundle subdirectory, and limited to global resources and those associated with the specified localization.)
同上一个方法,不同的是添加了本地资源文件的信息
- (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)ext subdirectory:(NSString *)subpath localization:(NSString *)localizationName

33、根据文件的后缀名称和子目录,获取一个NSURL 的数组
- (NSArray *)URLsForResourcesWithExtension:(NSString *)ext subdirectory:(NSString *)subpath
34、同上面的方法,添加了本地化的一个资源文件
- (NSArray *)URLsForResourcesWithExtension:(NSString *)ext subdirectory:(NSString *)subpath localization:(NSString *)localizationName

35、根据资源文件的名称,或者是文件的后缀名称以及目录的路径,获取 path
+ (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)bundlePath;

36、根据文件的扩展名,以及资源的路径,获取一个数组
+ (NSArray *)pathsForResourcesOfType:(NSString *)ext inDirectory:(NSString *)bundlePath;

37、根据文件的名称和扩展名获取 path 名称
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext;

37、根据文件的名称和扩展名获取 path 名称
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath;

37、根据文件的名称和扩展名获取 path 名称
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName;

38、根据文件的扩展名和子目录获取一个资源文件的数组
- (NSArray *)pathsForResourcesOfType:(NSString *)ext inDirectory:(NSString *)subpath;

39、同上,添加了资源文件的一个路径
- (NSArray *)pathsForResourcesOfType:(NSString *)ext inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName;
40、方法调用解释如下
- (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/iPhone Simulator/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/Application%20Support/iPhone%20Simulator/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/iPhone Simulator/6.1/Applications/2F3DA58F-5CF9-48A2-ADB2-C923A29B519E/IOS_Example_NSBundle.app";
   NSBundleResolvedPath = "/Users/ctrip1/Library/Application Support/iPhone Simulator/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、根据key 值获取本地化资源对象的值
- (id)objectForInfoDictionaryKey:(NSString *)key;

43、(官方描述:Returns the Class object for the specified name.根据类名字符串获取一个类对象)
- (Class)classNamed:(NSString *)className;
44、返回主要的类
- (Class)principalClass;
45、返回本地化资源的列表
- (NSArray *)localizations;
46、本地化的语言列表
- (NSArray *)preferredLocalizations;
47、使用创建的类获取本地化语言
- (NSString *)developmentLocalization;
48、(官方描述 Returns one or more localizations from the specified list that a bundle object would use to locate resources for the current user.)
+ (NSArray *)preferredLocalizationsFromArray:(NSArray *)localizationsArray;
+ (NSArray *)preferredLocalizationsFromArray:(NSArray *)localizationsArray forPreferences:(NSArray *)preferencesArray;

NSBundle常用方法及解释的更多相关文章

  1. JavaScript基础(一)之语法、变量、数据类型

    1.JavaScript语法 ①区分大小写 ②弱类型变量 ③每行结尾分号可有可无 ④括号用于代码块 ⑤注释有两种方式(单行和多行注释) 2.JavaScrip变量 ①用Var声明,不要初始化 ②可以在 ...

  2. jQuery插件主要有两种扩展方式

    jQuery插件主要有两种扩展方式: 扩展全局函数方式. 扩展对象方法方式. 扩展全局函数方式 扩展全局函数方式定义的插件,即类级别插件,可以通过jQuery.extend()来进行定义.定义格式为: ...

  3. Android数据存储:SDCard

    Android数据存储之SDCard 0.获取sd卡路径. 1.讲述 Environment 类. 2.讲述 StatFs 类. 3.完整例子读取 SDCard 内存 0.获取sd卡路径 方法一: p ...

  4. android 获取sd卡根目录

    dir:/storage/emulated/0 也就是 sdcard目录 ====== android 获取sd卡根目录 public String getSDPath(){        File ...

  5. Android获取SD卡路径及SDCard内存的方法

    这篇文章主要介绍了Android获取SD卡路径及SDCard内存的方法,较为详细的分析了Android针对SD卡操作所涉及的类及其具体函数功能,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了A ...

  6. SD卡路径问题以及如何获取SDCard 内存

            昨天在研究拍照后突破的存储路径的问题,开始存储路径写死为:    private String folder = "/sdcard/DCIM/Camera/"(SD ...

  7. Java ArrayList和LinkedList

    目录 集合的概念 集合体系结构 常用list集合 list集合的特点 ArrayList LinkedList 创建对象 常用方法 遍历 ArrayList和LinkedList的区别 集合的概念 ​ ...

  8. Java 常用Set集合和常用Map集合

    目录 常用Set集合 Set集合的特点 HashSet 创建对象 常用方法 遍历 常用Map集合 Map集合的概述 HashMap 创建对象 常用方法 遍历 HashMap的key去重原理 常用Set ...

  9. js中Prototype属性解释及常用方法

    1.prototype的定义 javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用. 每一个构造函数都有一个属 ...

随机推荐

  1. .html()和.text()的区别

    在页面调用接口显示数据的时候,正常情况下.html()和.text()都可以显示数据内容,但是在特殊情况下,比如接口中这个参数为空的时候就表现出差距了,.html()显示的是空白,而.text()显示 ...

  2. Spring对 JDBC 的支持,JdbcTemplate类的使用

    导包:spring框架的包 和 连接数据库连接池的c3p0包 连接mysql数据库的包; 在src目录下建立jdbc.properties文件:存放连接数据库的属性值 jdbc.user=root j ...

  3. cat > file << EOF 的用法

    cat> 文件名<<eof 用来创建文件在这之后输入任何东西 都是在 文件里的输入完成之后EOF结尾 代表结束比如cat > 1.txt <<eof12345eof ...

  4. 游戏笔记之《Fez》

    FEZ 游戏名称:菲斯 英文名称:Fez 游戏类型:ACT(动作游戏),AVG(冒险游戏) 游戏制作:Polytron Corporation 游戏发行:Trapdoor 游戏平台:PC 游戏画面: ...

  5. ORACLE常见数据类型详解

    1.字符类型 • CHAR:一个定长字符串,当位数不足自动用空格填充来达到其最大长度.如非NULL的CHAR(12)总是包含12字节信息.CHAR字段最多可以存储2,000字节的 信息. • VARC ...

  6. 记录js学习之this用法

    一直对Javascript中的this都有一种似是而非的感觉,今天突然感觉豁然开朗,特此记录一下. 咱们先看个栗子:    <!DOCTYPE html><html><h ...

  7. 稳定灵活的 HTML 列式布局

    主要特点: 所有列轻松实现相同高度 兼容性极高 ------------------------------------------------ 代码 ------------------------ ...

  8. zt:synpify 综合,保持信号,时序处理

    http://www.actel.com/kb/article.aspx?id=TT1002 Logic Replication vs. Preserve Attributes in Synplici ...

  9. 45、Docker 加 tensorflow的机器学习入门初步

    [1]最近领导天天在群里发一些机器学习的链接,搞得好像我们真的要搞机器学习似的,吃瓜群众感觉好神奇呀. 第一步 其实也是最后一步,就是网上百度一下,Docker Toolbox,下载下来,下载,安装之 ...

  10. 多媒体(2):WAVE文件格式分析

    目录 多媒体(1):MCI接口编程 多媒体(2):WAVE文件格式分析 多媒体(3):基于WindowsAPI的视频捕捉卡操作 多媒体(4):JPEG图像压缩编码 多媒体(2):WAVE文件格式分析