NSBundle
属性:
、使用类方法创建一个NSBundler对象
+ (NSBundle *)mainBundle;
eg:[NSBundle mailBundle];
、使用路径获取一个NSBundle 对象,这个路径应该是一个目录的全路径
+ (NSBundle *)bundleWithPath:(NSString *)path;
eg:
NSString *path = [mailBundle resourcePath];
NSBundle *language = [NSBundle bundleWithPath:path];
、使用路径初始化一个NSBundle
- (id)initWithPath:(NSString *)path; 、使用一个url 创建并初始化一个NSBundle对象(这是一个类方法)
注:这里的url 是一个特殊的 文件url路径
+ (NSBundle *)bundleWithURL:(NSURL *)url
、使用一个url 初始化一个NSBundle对象
注:这里的url 是一个特殊的 文件url路径
- (id)initWithURL:(NSURL *)url
、根据一个特殊的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>
、获取特定名称的bundle
+ (NSBundle *)bundleWithIdentifier:(NSString *)identifier;
、使用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)"
)
、获取应用程序加载的所有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)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/JavaScriptCore.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/AggregateDictionary.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/WebCore.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/SpringBoardServices.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/UIFoundation.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/DictionaryServices.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/lib> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/Foundation.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/IMFoundation.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/QuartzCore.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/CoreVideo.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/OpenGLES.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/WebBookmarks.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/CoreFoundation.framework> (loaded)",
"NSBundle </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)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/TelephonyUtilities.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/CFNetwork.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/CoreText.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/WebKit.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/PrivateFrameworks/MobileAsset.framework> (loaded)",
"NSBundle </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/CoreTelephony.framework> (loaded)"
) 、判断bundle 加载,(按照官方文档,You don’t need to load a bundle’s executable code to search the bundle’s resources.我们不需要调用这个方法,)
- (BOOL)load; 、判断bundle 加载
- (BOOL)isLoaded; 、判断bundle 加载
- (BOOL)unload; 、加载资源,如果有错误的话,会放置错误信息
- (BOOL)preflightAndReturnError:(NSError **)error
- (BOOL)loadAndReturnError:(NSError **)error
、获取bundle 类实例的 url
- (NSURL *)bundleURL 、获取bundle 类实例的 resourceUrl 资源
- (NSURL *)resourceURL 、获取bundle 类实例的 可执行的URL
- (NSURL *)executableURL 、(Returns the file URL of the executable with the specified name in the receiver’s bundle.返回一个,文件的URL,使用一个特殊的名称)
- (NSURL *)URLForAuxiliaryExecutable:(NSString *)executableName 、获取当前NSBundle实例的 URL 资源
- (NSURL *)privateFrameworksURL
、获取共享的frameworkdURL
- (NSURL *)sharedFrameworksURL
、 获取支持的Bundle的Url
- (NSURL *)sharedSupportURL
、获取添加插件的URL
- (NSURL *)builtInPlugInsURL
// 已经不能使用,
- (NSURL *)appStoreReceiptURL
、 获取bundle 的path 路径
- (NSString *)bundlePath; 、获取bundle 的资源路径字符串
- (NSString *)resourcePath; 、获取bundle 可执行文件路径
- (NSString *)executablePath; 、获取bundle 辅助的path
- (NSString *)pathForAuxiliaryExecutable:(NSString *)executableName; 、获取私有的路径框架
- (NSString *)privateFrameworksPath;
、获取共享的framework path 路径
- (NSString *)sharedFrameworksPath; 、获取共享的路径
- (NSString *)sharedSupportPath; 、获取插件的路径
- (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 、使用bundle 创建一个资源文件的URL
- (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)ext
eg:
NSURL* URL=[[NSBundle mainBundle] URLForResource:fileName withExtension:@"png"];
、(官方描述如下: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 、(官方描述:
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 、根据文件的后缀名称和子目录,获取一个NSURL 的数组
- (NSArray *)URLsForResourcesWithExtension:(NSString *)ext subdirectory:(NSString *)subpath
、同上面的方法,添加了本地化的一个资源文件
- (NSArray *)URLsForResourcesWithExtension:(NSString *)ext subdirectory:(NSString *)subpath localization:(NSString *)localizationName 、根据资源文件的名称,或者是文件的后缀名称以及目录的路径,获取 path
+ (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)bundlePath; 、根据文件的扩展名,以及资源的路径,获取一个数组
+ (NSArray *)pathsForResourcesOfType:(NSString *)ext inDirectory:(NSString *)bundlePath; 、根据文件的名称和扩展名获取 path 名称
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext; 、根据文件的名称和扩展名获取 path 名称
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath; 、根据文件的名称和扩展名获取 path 名称
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName; 、根据文件的扩展名和子目录获取一个资源文件的数组
- (NSArray *)pathsForResourcesOfType:(NSString *)ext inDirectory:(NSString *)subpath; 、同上,添加了资源文件的一个路径
- (NSArray *)pathsForResourcesOfType:(NSString *)ext inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName;
、方法调用解释如下
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName NS_FORMAT_ARGUMENT(); 你可以通过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 = ;
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 = (
, );
UIRequiredDeviceCapabilities = (
armv7
);
UISupportedInterfaceOrientations = (
UIInterfaceOrientationPortrait,
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight
);
} 、返回本地化资源的NSDictionary 对象
- (NSDictionary *)localizedInfoDictionary; 、根据key 值获取本地化资源对象的值
- (id)objectForInfoDictionaryKey:(NSString *)key; 、(官方描述:Returns the Class object for the specified name.根据类名字符串获取一个类对象)
- (Class)classNamed:(NSString *)className;
、返回主要的类
- (Class)principalClass;
、返回本地化资源的列表
- (NSArray *)localizations;
、本地化的语言列表
- (NSArray *)preferredLocalizations;
、使用创建的类获取本地化语言
- (NSString *)developmentLocalization;
、(官方描述 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的更多相关文章
- iOS在线更新framework,使用NSBundle动态读取
官方文档:https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingCode/Tasks/Loadin ...
- iOS 整理笔记 获取手机信息(UIDevice、NSBundle、NSLocale)
/* iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发ap ...
- -[NSBundle initWithURL:]: nil URL argument'
今天早上同事突然跟我说趣拍的SDK不能用了,一调用就crash,我一听就纳了闷了,原来好好的啊. 然后就开始查呗,马上就要上线了,不搞好,老大会不会杀了我... 搞个全局断点,就停在了一堆我看不懂的界 ...
- iOS的UIDevice,NSBundle,NSLocale
iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用 户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发api可以获取 ...
- NSBundle常用方法及解释
1.使用类方法创建一个NSBundler对象+ (NSBundle *)mainBundle;eg:[NSBundle mailBundle];2.使用路径获取一个NSBundle 对象,这个路径应该 ...
- NSBundle控件和UIImageView和UIButton区别
1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应 ...
- iOS [[NSBundle mainBundle] pathForResource:@"" ofType:@""]无法获取到文件
将一个文件导入到工程中后,用[[NSBundle mainBundle] pathForResource:@"" ofType:@""]来获取到该文件时,一直无 ...
- iOS- Could not find a storyboard named 'Main' in bundle NSBundle
1.删掉工程中main.storyboard 后要删除plist文件中对应的键值,否则会报如下错误: Could not find a storyboard named 'Main' in bundl ...
- NSBundle/其他Bundle的获取
#define D_SharkItOffViewControllerBundleName @"SharkItOffViewController.bundle" //套装名称 //其 ...
随机推荐
- gif jpg bmp png的区别
PNG格式图片因其高保真性.透明性及文件大小较小等特性,被广泛应用于网页设计.平面设计中.网络通讯中因受带宽制约,在保证图片清晰.逼真的前提下,网页中不可能大范围的使用文件较大的bmp.jpg格式文件 ...
- thinkcmf开发--关于控制器
一.安装 安装---删除install文件--删除index.php--修改数据库信息--创建数据库 修改数据库信息:\data\conf\db.php(包括服务器地址) 二.创建mobile app ...
- Bootstrap之样式风格与下拉菜单
背景颜色 bg-primary 字体颜色 text-primary 文字居中 text-center 按钮 btn btn-primary btn-default默认 btn-link链接 按钮大小 ...
- Javascript中构造函数与new命令
典型的面向对象编程语言(比如C++和Java),存在“类”(class)这个概念.所谓“类”就是对象的模板,对象就是“类”的实例.但是,在JavaScript语言的对象体系,不是基于“类”的,而是基于 ...
- 网络天荒地老之UIWebView&WebKit
UIWebView 是苹果提供的用来展示网页的UI控件,它也是最占内存的控件. iOS8.0之后出现了webkit框架,WKWebView相比UIWebView节省了1/4~1/3的内存,速度快,但是 ...
- JDBC快速入门
/** * JDBC快速入门: * 1.导入jar包 数据库驱动 * 2.注册驱动 * 3.获取数据库连接对象 Connection * 4.定义sql语句 * 5.获取发送执行sql语句的对象 St ...
- HTML5-01 简介
标记语言 概述 标记语言(也称置标语言),是一种将文本及文本相关的其他信息结合起来,展现出关于文档结构和数据处理细节的计算机编码.与文本相关的其他信息(包括例如文本的结构和表示信息等)与原来的文本结合 ...
- MS SQL 2008 发布订阅配置错误总结
最近在配置SQL 2008的发布订阅功能时,遇到了几个小错误,顺便归纳总结一下(以后碰到各类关于发布订阅的错误都将收录.更新到这篇文章),方便自己在以后碰到这类问题时,能够迅速解决问题.毕 ...
- MongoDB学习笔记~官方驱动的原生Curd操作
回到目录 MongoDB的官方C#驱动,让我们使用起来也很方便,但对于Linq开发人员来说,可能有些不了解,所以,我还是将官方驱动进行了二次封装,而对于一个比较个性化的mongo操作,使用我封装的也很 ...
- 一则uiautomation错误处理
一款iphone程序,用到了多window,结果在最后一个window里设置textfield时出错 target.frontMostApp().mainWindow().textFields()[0 ...