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);
  • 相关阅读:
    C#读写txt文件的两种方法介绍
    C#委托的介绍(delegate、Action、Func、predicate)
    C#邮件发送
    ASP.NET 文件上传于下载
    关于Virtual Box虚拟机里的系统不能启动的解决方法
    unity的yield
    unity文件路径
    手机上的unity路径
    readonly
    unity延迟加载图片
  • 原文地址:https://www.cnblogs.com/xieyier/p/4194219.html
Copyright © 2011-2022 走看看