zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    SVN项目提交报错
    Post请求报文压缩
    mysql表结构的修改-sql记录
    项目内添加quartz定时任务
    Nginx配置-通过nginx访问项目
    Mysql的使用 -简单的索引
    使用git第一次成功,记录
    Spring P命名空间 02
    Mybatis 一级、二级缓存
    延迟加载
  • 原文地址:https://www.cnblogs.com/xieyier/p/4194219.html
Copyright © 2011-2022 走看看