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