//获取沙盒主路径
NSString *homePath = NSHomeDirectory();
NSLog(@"homePath:%@",homePath);
//获取document路径
//返回是一个数组,iOS端只有一个document,为什么返回的是数组呢,是因为Mac端和iOS端都是用同一门语言,在Mac端是可以有多个document的,所以返回的是数组。
//第一个参数表示的是一个路径
//第二个参数表示的是是主人用户还是客人用户,在iOS端也是只有一个用户
//NSSearchPathForDirectoriesInDomains(<#NSSearchPathDirectory directory#>, <#NSSearchPathDomainMask domainMask#>, <#BOOL expandTilde#>)
//第三个参数:YES 显示完整路径, NO 显示相对路径
//document:通常用来存放应用程序需要持久化使用的关键数据,比如本地数据库等。
//iTunes在备份的时候会自动备份此文件夹。
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, NO) objectAtIndex:0];
NSLog(@"document:%@",documentPath);
//libray:通常用来存储应用程序运行期间生成的持久化数据,比如用户账户名等。应用程序退出后不会被删除文件夹内数据,
//但是iTunes备份时不会备份此文件夹。
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, NO) objectAtIndex:0];
NSLog(@"library:%@",libraryPath);
//cache:运行期间的缓存文件、历史记录等。
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, NO) objectAtIndex:0];
NSLog(@"cache:%@",cachePath);
//preferences:应用程序的设置,比如夜间模式等。
//tmp:存放临时文件,应用程序结束后清除。
NSString *tmpPath = NSTemporaryDirectory();
NSLog(@"tmp%@",tmpPath);
#pragma mark Bundle
//获取当前应用程序
NSBundle *bundle = [NSBundle mainBundle];
//获取当前包得路径
NSString *bundlePath = [bundle resourcePath];
NSLog(@"bundlePath:%@",bundlePath);
//或者
NSString *bundlePathA = [bundle bundlePath];
NSLog(@"bundlePathA:%@",bundlePathA);
//资源路径:图片路径
NSString *imagePath = [bundle pathForResource:@"background@2x" ofType:@"png"];
NSLog(@"imagePath:%@",imagePath);
//
NSString *interfacePath = [bundle pathForResource:@"News" ofType:@"txt"];
NSLog(@"interfacePath:%@",interfacePath);