Bundle,即一个文件夹目录,包含图像、声音、编译好的代码。
1、获取Bundle
//在程序中获得main bundle
NSBundle bundle = [NSBundle mainBundle];
//获取其他目录的bundle
NSBundle otherBundle = [NSBundle bundleWithPath:@"~/.myApp/Good.bundle"];
2、获取resource
NSString
*earth
= [[
NSBundle
mainBundle]
pathForResource:@
"Brad
Cox"
ofType:@
"png"
];//mainBundle的资源都是放到RootFolder下,所以,可以直接访问,不要指定内部路径
NSString
*earth
= [[
NSBundle
mainBundle]
pathForResource:@
"Brad
Cox"
ofType:@
"png"
inDirectory:@"Images/MoreImages"];//获取customer目录里的资源
3、获取应用程序相关信息
NSDictionary *appDictionary = [[NSBundle mainBundle] infoDictionary]; //获取程序plist文件
NSString * path =[ [NSBundle mainBundle] bundlePath] ; //获取程序app包路径
NSString * resPath =[ [NSBundle mainBundle] resourcePath] ; //获取应用程序资源目录