获取文件资源的各种方式

 1.获取工程info文件

    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];

    eg: 版本号

    NSString *version = [infoDic objectForKey:kCFBundleVersionKey];


2.获取设备信息

   UIDevice *device = [UIDevice currentDevice];

   eg: 设备当前安装的系统,如6.1 、7.1 等等

   NSString * systemVersion = [[UIDevice currentDevice] systemVersion]

    设备类型:iphone ipod

    NSString * model = [[UIDevice currentDevice] model];

    设备标识:

    NSString * udidStr =  [[UIDevice currentDevice] identifierForVendor].UUIDString;



3. 获取资源文件(Bundle Resource中添加的文件)

    NSString *path = [[NSBundle mainBundle]resourcePath];

    NSString *filePath = [[NSString alloc]initWithFormat:@"%@/%@",path,file];

   NSDictionary * _urlDict = [NSDictionary dictionaryWithContentsOfFile:filePath];

   

  获取工程中得本地文件中的指定文件

   NSString *path =  [[NSBundle mainBundle]pathForResource:fileName ofType:type ];

   NSMutableArray *mutArr = [[NSMutableArray alloc]initWithContentsOfFile:filePath];//取出数据


  获取沙河中的文件

   //(1)指定文件夹,(2)设置查找域,(3)是否使用详细路径

    NSArray *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsPath = document[0];

    //拼接上要存储的文件路径(前面自动加上/),如果没有此文件系统会自动创建一个

    NSString *newFielPath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",filename]];


   自定义对象归档到沙河:[NSKeyedArchiver archiveRootObject:data toFile:newFielPath];//把data存入filename

   自定义对象从沙河解档:id obj = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];

   基本对象写入沙河:[obj writeToFile:filePath atomically:YES encoding:NSStringEncodingConversionOptions error:nil];

   从沙河读出数据:NSMutableArray  *dict = [NSMutableArray arrayWithContentsOfFile:newFielPath];


你可能感兴趣的:(ios,nsbundle,uidevice,NSKeyedArchiver,infoDictionary)