iOS中NSBundle类

An NSBundle object represents a location in the file system that groups code and resources that can be used in a program. NSBundle objects locate program resources, dynamically load and unload executable code, and assist in localization. You build a bundle in Xcode using one of these project types: Application, Framework, plug-ins.
Overview
Although bundle structures vary depending on the target platform and the type of bundle you are building, the NSBundle class hides this underlying structure in most (but not all) cases. Many of the methods you use to load resources from a bundle automatically locate the appropriate starting directory and look for resources in known places. For information about application bundle structures (for OS X and iOS), see Bundle Programming Guide. For information about the structure of framework bundles, see Framework Programming Guide. For information about the structure of OS X plug-ins, see Code Loading Programming Topics.
For additional information about how to load nib files and images in a Mac app, see NSBundle AppKit Additions Reference. For information about how to load nib files in an iOS application, see NSBundle UIKit Additions Reference.
Unlike some other Foundation classes with corresponding Core Foundation names (such as NSString and CFString), NSBundle objects cannot be cast (“toll-free bridged”) to CFBundle references. If you need functionality provided in CFBundle, you can still create a CFBundle and use the CFBundle Reference API. See Interchangeable Data Types for more information on toll-free bridging.

一、mainBundle

获取方法是NSBundle的静态方法:

+ (NSBundle *)mainBundle;
Overview:
Returns the NSBundle object that corresponds to the directory where the current application executable is located.
The NSBundle object that corresponds to the directory where the application executable is located, or nil if a bundle object could not be created.返回到目录当前的应用程序可执行文件所在的位置相对应的 NSBundle 对象。

info.plist打印:

[[NSBundle mainBundle] infoDictionary]
{
    BuildMachineOSBuild = 15B42;
    CFBundleDevelopmentRegion = en;
    CFBundleExecutable = Vuforia;
    CFBundleIcons =     {
        CFBundlePrimaryIcon =         {
            CFBundleIconFiles =             (
                AppIcon29x29,
                AppIcon40x40,
                AppIcon57x57,
                AppIcon60x60
            );
        };
    };
    CFBundleIdentifier = "com.vuforia.sample.Vuforia";
    CFBundleInfoDictionaryVersion = "6.0";
    CFBundleInfoPlistURL = "Info.plist -- file:///var/mobile/Containers/Bundle/Application/37BA0E72-E0C6-4D56-BA12-430F36CED547/Vuforia.app/";
    CFBundleName = Vuforia;
    CFBundleNumericVersion = ;
    CFBundlePackageType = APPL;
    CFBundleShortVersionString = "5.0";
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
        iPhoneOS
    );
    CFBundleVersion = ;
    DTCompiler = "com.apple.compilers.llvm.clang.1_0";
    DTPlatformBuild = 13C75;
    DTPlatformName = iphoneos;
    DTPlatformVersion = "9.2";
    DTSDKBuild = 13C75;
    DTSDKName = "iphoneos9.2";
    DTXcode = ;
    DTXcodeBuild = 7C68;
    LSRequiresIPhoneOS = ;
    MinimumOSVersion = "7.0";
    UIDeviceFamily =     (
        ,

    );
    UILaunchImageFile = LaunchImage;
    UILaunchImages =     (
                {
            UILaunchImageMinimumOSVersion = "8.0";
            UILaunchImageName = "LaunchImage-800-Portrait-736h";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{414, 736}";
        },
                {
            UILaunchImageMinimumOSVersion = "8.0";
            UILaunchImageName = "LaunchImage-800-Landscape-736h";
            UILaunchImageOrientation = Landscape;
            UILaunchImageSize = "{414, 736}";
        },
                {
            UILaunchImageMinimumOSVersion = "8.0";
            UILaunchImageName = "LaunchImage-800-667h";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{375, 667}";
        },
                {
            UILaunchImageMinimumOSVersion = "7.0";
            UILaunchImageName = "LaunchImage-700";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{320, 480}";
        },
                {
            UILaunchImageMinimumOSVersion = "7.0";
            UILaunchImageName = "LaunchImage-700-568h";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{320, 568}";
        },
                {
            UILaunchImageMinimumOSVersion = "7.0";
            UILaunchImageName = "LaunchImage-700-Portrait";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{768, 1024}";
        },
                {
            UILaunchImageMinimumOSVersion = "7.0";
            UILaunchImageName = "LaunchImage-700-Landscape";
            UILaunchImageOrientation = Landscape;
            UILaunchImageSize = "{768, 1024}";
        }
    );
    UIMainStoryboardFile = Main;
    UIRequiredDeviceCapabilities =     (
        armv7
    );
    UIStatusBarHidden = ;
    UISupportedInterfaceOrientations =     (
        UIInterfaceOrientationPortrait
    );
    UIViewControllerBasedStatusBarAppearance = ;
}

info.plist打印结果

可以通过这个东西来获得app的info信息。enjoy it:)

二、customBundle

图片的压缩包bundle东西,例如:QQ的app的个性化定制图片资源,一些加载的可执行的代码(这个我没有操作过)。

如何加载customBundle看NSBundle中的公开方法。

mainBundle和CustomBundle的更多相关文章

  1. iOS [[NSBundle mainBundle] pathForResource:@"" ofType:@""]无法获取到文件

    将一个文件导入到工程中后,用[[NSBundle mainBundle] pathForResource:@"" ofType:@""]来获取到该文件时,一直无 ...

  2. NSBundle的使用,注意mainBundle和Custom Bundle的区别

    1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...

  3. [[NSBundle mainBundle] pathForResource:fileName ofType:]获取文件路径不成功

    目标文件明明已经加入项目了,但是使用[[NSBundle mainBundle] pathForResource:fileName ofType:]来获取文件路径的时候却为nil: 遇到这个问题大家需 ...

  4. IOS NSBundle的使用,注意mainBundle和Custom Bundle的区别

    1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...

  5. IOS NSBundle 的理解和 mainBundle 类方法详解

    常看到类似的 NSString *file = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 这样的代码,用来获取 file 的完全 ...

  6. NSBundle的理解和mainBundle的基本介绍

    一.NSBundle NSBundle是cocoa为bundle提供的一个类,bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像.声音.编译好的代码.nib文件.(用户也会把 ...

  7. [[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"] 找不到对应的文件解决方法

    最近在使用[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]时,找不到其对应的文件,文 ...

  8. 【转】NSBundle的使用,注意mainBundle和Custom Bundle的区别

    1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...

  9. iOS 把数据库文件打包到mainbundle中,查找不到路径的解决的方法;以及在删除bundle中文件的可行性

    在开发中有时我们须要把数据库文件打包到我们的项目中.一般我们都是在外部用工具生成数据库文件,然后拉入项目中.可是我们在程序中查找改文件时.返回的路径总是nil 解决的方法: 原因我们拉入其它资源文件( ...

随机推荐

  1. 基于nodejs的终端天气查询

    国际惯例,先上效果图 前天,突然想到,怎么直接在命令行查询天气呢?好的,那就写一个吧.然后就开始找城市.天气的api接口,最终做出来这么一个东西. 安装方法:$ npm install tianqi ...

  2. JavaScript中的算法之美——栈、队列、表

    序 最近花了比较多的时间来学习前端的知识,在这个期间也看到了很多的优秀的文章,其中Aaron可能在这个算法方面算是我的启蒙,在此衷心感谢Aaron的付出和奉献,同时自己也会坚定的走前人这种无私奉献的分 ...

  3. Bootstrap系列 -- 9. 表格

    一. Bootstrap 表格样式支持 Bootstrap提供了六种不同风格的样式支持,其中一个基础样式,4个附件样式,1个响应式设计样式 1. .table:基础表格 2. .table-strip ...

  4. foreach 和 for 循环的区别

    foreach 依赖 IEnumerable. 第一次 var a in GetList() 时 调用 GetEnumerator 返回第一个对象 并 赋给a, 以后每次再执行 var a in Ge ...

  5. 东大OJ-Max Area

    1034: Max Area 时间限制: 1 Sec  内存限制: 128 MB 提交: 40  解决: 6 [提交][状态][讨论版] 题目描述 又是这道题,请不要惊讶,也许你已经见过了,那就请你再 ...

  6. oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务。

    来源于:http://www.cnblogs.com/wangfg/p/5110831.html 一.查询系统中的job,可以查询视图 --相关视图 select * from dba_jobs; s ...

  7. [转]JAVA设计模式之单例模式

    原文地址:http://blog.csdn.net/jason0539/article/details/23297037 概念: java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主 ...

  8. ActiveMQ(七)_伪集群和主从高可用使用

      一.本文目的         介绍如何在同一台虚拟机上搭建高可用的Activemq服务,集群数量包含3个Activemq,当Activemq可用数>=2时,整个集群可用.         本 ...

  9. 谈谈MVC项目中的缓存功能设计的相关问题

    本文收集一些关于项目中为什么需要使用缓存功能,以及怎么使用等,在实际开发中对缓存的设计的考虑 为什么需要讨论缓存呢? 缓存是一个中大型系统所必须考虑的问题.为了避免每次请求都去访问后台的资源(例如数据 ...

  10. Android中图像变换Matrix的原理、代码验证和应用(二)

    第二部分 代码验证 在第一部分中讲到的各种图像变换的验证代码如下,一共列出了10种情况.如果要验证其中的某一种情况,只需将相应的代码反注释即可.试验中用到的图片: 其尺寸为162 x 251. 每种变 ...