IOS文件系统
2015-08-12 18:40
465 查看
IOS文件系统
当开发者第一次启动app时,IOS操作系统就为此app创建了一个文件系统,该文件系统下默认有四个,分别是:Documents:存储用户在操作app时产生的数据,使目录下的数据可以通过iCloud进行同步。
Library:用户偏好设置数据,通常和此类NSUserDefaults搭配使用,此目录下的数据可以通过iCloud进行同步。
Tmp:存在临时数据,此目录下的数据不会通过iCloud进行同步。
Ipa包:开发者不会操作此目录,通常是通过此类NSBundle类。
//获取程序根目录 NSString *homePath = NSHomeDirectory();
//获取根目录下的Documents目录 NSString *documentsPath = [homePath stringByAppendingPathComponent:@"Documents"]; //或者 documentsPath = [homePath stringByAppendingFormat:@"/Documents"];
//最常用的获取Documents目录 documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSLog(@"documentPath = %@",documentsPath);
//字符串拼接
NSString *libraryPath = [homePath stringByAppendingString:@”Documents”];
//C函数获取Library目录
libraryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) objectAtIndex:0];
libraryPath = [homePath stringByAppendingString:@"/library"]; NSLog(@"libraryPath = %@",libraryPath); //获取tmp目录 NSString *tmpPath = NSTemporaryDirectory();
//app包,获取包内的图片,显示在UI上 NSBundle *bundle = [NSBundle mainBundle]; NSLog(@"bundlePath = %@",bundle.bundlePath); NSString *imgPath = [bundle pathForResource:@"5.pic" ofType:@"jpg"]; NSData *imgData = [NSData dataWithContentsOfFile:imgPath]; UIImage *image = [UIImage imageWithData:imgData]; self.imageView.image = image;
相关文章推荐
- 【读书笔记】iOS-截屏功能的实现。
- 【读书笔记】iOS-截屏功能的实现。
- iOS_关联使用(一)
- iOS_关联使用(二)
- iOS之ViewController的多层presentViewController的dismiss问题
- iOS 中 setter and getter
- ios开发中全局变量的使用
- iOS常用的第三方框架
- IOS #import与#include和@class的区别
- IOS动画CABasicACnimationanimation
- iOS内存管理策略和实践
- IOS的水滴文件效果
- 安装nagios 登陆后提示nagios Internal Server Error
- iOS跳转到打电话
- iOS竖屏自动滚动或欢迎页
- iOS Crash文件分析]-如何使用symbolicatecrash工具
- iOS开发系列--地图与定位
- iOS 版本自动更新
- iOS正则匹配手机号
- 如何学习IOS