NSBundle 的使用

NSBundle 读取图片 plist text

    NSBundle *mainbundle=[NSBundle mainBundle];
//使mainBundle 对象获取图片的路径
NSString *imagePath=[mainbundle pathForResource:@"coffe" ofType:@"png"];
//使用mainBundle 对象获取到 plist 文件的路径
NSString *plistPath=[mainbundle pathForResource:@"testplist" ofType:@"plist"];
//使用mainbundle 对象获取到 TXT 文件路径;
NSString *txtPath=[mainbundle pathForResource:@"testText" ofType:@"txt"];

处理上面路径;

//处理以上路径的资源
//imagePath
UIImage *image=[[UIImage alloc] initWithContentsOfFile:imagePath];
//plistPath 将plist 文件的内容读到字典中去;
NSMutableDictionary *data=[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(@"%@",data); //textpath 将text 文件内容输出到字符串中
NSString *txtcontents=[[NSString alloc] initWithContentsOfFile:txtPath encoding:NSUTF8StringEncoding error:nil];

通过路径获取到APP的信息如 版本号 ;

    NSDictionary *dicAppInfo=[[NSBundle mainBundle] infoDictionary];
NSString *AppName=[dicAppInfo objectForKey:@"CFBundleDisplayName"];
NSString *AppVersion=[dicAppInfo objectForKey:@"CFBundleShortVersionString"];
NSString *AppBuild=[dicAppInfo objectForKey:@"CFBundleVersion"]; NSLog(@"APP应用的名称:%@",AppName);
NSLog(@"APP应用的版本号为:%@",AppVersion);
NSLog(@"APP应用的build版本号为:%@",AppBuild);
上一篇:Go学习笔记(一)Let's 干


下一篇:C# 读取Excel