mainBundle和CustomBundle

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 = 16809984;
    CFBundlePackageType = APPL;
    CFBundleShortVersionString = "5.0";
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
        iPhoneOS
    );
    CFBundleVersion = 1;
    DTCompiler = "com.apple.compilers.llvm.clang.1_0";
    DTPlatformBuild = 13C75;
    DTPlatformName = iphoneos;
    DTPlatformVersion = "9.2";
    DTSDKBuild = 13C75;
    DTSDKName = "iphoneos9.2";
    DTXcode = 0720;
    DTXcodeBuild = 7C68;
    LSRequiresIPhoneOS = 1;
    MinimumOSVersion = "7.0";
    UIDeviceFamily =     (
        1,
        2
    );
    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 = 1;
    UISupportedInterfaceOrientations =     (
        UIInterfaceOrientationPortrait
    );
    UIViewControllerBasedStatusBarAppearance = 0;
}

info.plist打印结果

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

二、customBundle

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

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

时间: 2024-10-18 19:36:47

mainBundle和CustomBundle的相关文章

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

最近在使用[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]时,找不到其对应的文件,文件当时是通过 右键->add files to 的方式添加到工程里面的,但是使用[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]时,无论如何都找不到文件,经过了重启工程 .clear工程以

mainBundle使用

NSBundle:一个NSBundle代表一个文件夹 mainBundle可以访问软件资源包中的任何文件 //获得mainBundle NSBundle *bundle = [NSBundle mainBundle]; //  获得imageData.plist的全路径 NSString *path = [bundle pathForResource:@"fileName" ofType:@"文件类型"]; mainBundle使用,布布扣,bubuko.com

NSBundle 的理解和 mainBundle 类方法详解

常看到类似的 NSString *file = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 这样的代码,来产生 file 的完全路径. 那么它是什么东西呢:先看 NSBundle 类,直接继承NSObject类. 这个类的对象,代表了 app 中代码和资源的文件在文件系统里所在的位置,通俗的说,就是定位了程序使用的资源(代码,图形,音乐等数据)在文件系统里的位置,并可以动态的加载.or卸载掉可执行代码. 我们的程序是一个bun

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

1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth = [[NSBundle mainBundle] pathForResource:@"Brad Cox" ofType:@"png"]; 2.使用文件夹的时候,Build结果 依然使用同样的方法,不需要制定文件夹路径 //inDirectory参数可有可无 NSStr

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

在开发中有时我们需要把数据库文件打包到我们的项目中,一般我们都是在外部用工具生成数据库文件,然后拉入项目中,但是我们在程序中查找改文件时,返回的路径总是nil 解决办法: 原因我们拉入其他资源文件(比如:图片.代码文件等)Xcode都会自动添加到target 的 "Build Phases" 下 "Copy Bundle Resources目录下,但是我们拉过来的数据库文件这里是找不到的,可能是Xcode无法识别这类文件(当我们拉去过来时),所以我们要做的就是把刚才添加的db

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

常看到类似的 NSString *file = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 这样的代码,用来获取 file 的完全路径. 那么它是什么东西呢:先看 NSBundle 类,直接继承NSObject类. 这个类的对象,代表了 app 中代码和资源的文件在文件系统里所在的位置,通俗的说,就是定位了程序使用的资源(代码,图形,音乐等数据)在文件系统里的位置,并可以动态的加载.or卸载掉可执行代码. 我们的程序是一个bu

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

1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth = [[NSBundle mainBundle] pathForResource:@"Brad Cox" ofType:@"png"]; 2.使用文件夹的时候,Build结果 依然使用同样的方法,不需要制定文件夹路径 //inDirectory参数可有可无 NSStr

QLPreviewController加载mainBundle文件不显示问题 Couldn't issue file extension for url:

需要把文件copy到沙盒中再显示 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDir = [paths objectAtIndex:0]; NSString *path = [docDir stringByAppendingPathComponent:@"222.pdf"]; NSString *path2 =

关于[[NSBundle mainBundle] pathForResource:@"name"

http://blog.csdn.net/yangxuanlun/article/details/8938148