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安全沙盒的限制,所有的获取的资源,是应用程序的资源)
注:官方标注,获取所有的非frameworkbundle;

+ (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、 获取支持的BundleUrl

- (NSURL *)sharedSupportURL

21、获取添加插件的URL

- (NSURL *)builtInPlugInsURL
// 已经不能使用,
- (NSURL *)appStoreReceiptURL

22、 获取bundlepath路径

- (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;

iOS NSBundle常用方法及解释相关推荐

  1. ios学习--TableView详细解释

    2019独角兽企业重金招聘Python工程师标准>>> ios学习--TableView详细解释 分类: ios Object-C 2012-05-17 08:48  1714人阅读 ...

  2. iOS NSMutableAttributedString常用方法总结

    NSAttributedString 叫做富文本,是一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多种字体.字号.字体大小等各不相同的风格,还可以对段落进行格式化,一般都是对可变富文本(N ...

  3. iOS:NSBundle的具体介绍

    NSBundle介绍:它是一个单例类,用来加载资源 bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-i ...

  4. openGL学习笔记(1)——常用方法原型解释

    1.初始化,设置背景色 void glClear(int mask)    清除缓存 实參含义:GL10.GL_COLOR_BUFFER_BIT 清除颜色缓存 GL10.GL_DEPTH_BUFFER ...

  5. 浅谈 iOS 版本号

    FIR.im 一直在尽量兼容不同使用习惯的版本号形式, 但是在使用中我们发现好多开发者对怎么更好的用版本号来标示应用很陌生. 这是篇基础文章, 简单介绍 iOS 的版本号. 名词解释 Version, ...

  6. iOS - NetRequest 网络数据请求

    1.网络请求 1.1 网络通讯三要素 1.IP 地址(主机名): 网络中设备的唯一标示.不易记忆,可以用主机名(域名). 1) IP V4: 0~255.0~255.0~255.0~255 ,共有 2 ...

  7. (0107)iOS开发之UI实时调试InjectionIII的使用

    AppStore : 下载:Injectionlll 下载地址 使用步骤: 1.设置InjectionIII 打开InjectionIII工具,选择Open Project,选择你的代码所在的路径,然 ...

  8. ios是什么,ios是什么意思

    iOS是由苹果公司开发的移动操作系统 .苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计给iPhone使用的,后来陆续套用到iPod touch.iPad以及Apple ...

  9. iOS中MQTT和WS的简单混合使用

    历经三天的寻找和尝试,终于完成了一个任务,任务要求的服务器访问用WebSocket的URL格式的,而访问结束后要进行订阅和消息发送,这更多出现在MQTT协议的框架里,例如这个文章 https://ww ...

最新文章

  1. 循环求100内质数 php_C8循环
  2. python设计模式(三):原型模式—快速实例化类的一种途径
  3. 防止删库悲剧发生,这里有个Bash脚本测试框架,危险代码一测便知
  4. TCL with SNPS llengthlappendget_cellsget_ports
  5. [BUUCTF-pwn]——bbys_tu_2016
  6. jsp使用cookie实现记住用户名和密码
  7. jboss4 迁移_应用程序服务器迁移:从JBoss EE5到Wildfly EE7
  8. 【转】android 中如何限制 EditText 最大输入字符数
  9. java http 1.1_java11新特性HttpClient
  10. 下载、安装Keil 5
  11. 锤子不死!还有新手机,但要等很久...
  12. Qt使用QPainter实现雷达图(玫瑰图)
  13. 【天池大数据赛题解析】资金流入流出预测(附Top4答辩ppt)
  14. bzoj3514 Codechef MARCH14 GERALD07加强版 lct预处理+主席树
  15. 假设检验的基本原理和T检验
  16. vue项目中使用高德地图实现添加点标记和获取点击位置信息
  17. Windows_Program_Via_C_Translate_Win32编程的背景知识/基础知识_包括基本输入输出机制介绍...
  18. 谷歌浏览器打印不弹出预览直接打印机打印
  19. Fortran基础编程(3)——格式化输出
  20. 项目八总结 数据库安全与维护

热门文章

  1. 无人值守的IDC机房动环综合运维方案
  2. Openssl 对称加解密函数 - EVP_Cipher、EVP_Encrypt、EVP_Decryp 系列
  3. 【元胞自动机】基于元胞自动机模拟晶体生长附matlab代码
  4. 基于AT89C51最小系统的手机遥控车
  5. 上位机与下位机是什么?
  6. 单片机c语言中io取反,单片机小白学步(21) IO口:基本的LED和按键操作
  7. 毕业论文管理系统设计与实现(论文+源码)_kaic
  8. pc-com串口(DB9)管脚定义和单片机uart串口
  9. 自动化重复文件清理 Bash 脚本
  10. 分享五个404页面模板 超好看的404页面你的网站离不了 seo优化404