1. App Home(/AppBane,aoo)。包含App bundle的目录,不要在该路径下写任何文件。
2. /Documents/。使用该路径放置关键数据,也就是不能通过App重新生成的数据。该路径可通过配置实现iTunes共享文件。可被iTunes备份。(现在保存在该路径下的文件还需要考虑iCloud同步)
3. /Library/。该路径下一般保存着用户配置文件。可创建子文件夹。可以用来放置您希望被备份但不希望被用户看到的数据。该路径下的文件夹,除Caches以外,都会被iTunes备份。
4. /tmp/。使用该路径保存临时文件。App应该删除那些不再被使用的文件,系统也会在App关闭后删除残留文件。该路径下的文件不会被iTunes备份。
NSString *path = NSHomeDirectory();
上面的代码得到的是应用程序目录的路径,在该目录下有三个文件夹:Documents、Library、temp以及一个.app包!该目录下就是应用程序的沙盒,应用程序只能访问该目录下的文件夹!!!
请参考下面的例子:
1、
NSString *path1 = NSHomeDirectory();
NSLog(@"path1:%@", path1);
path1:/Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830
2、
NSString *path2 = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSLog(@"path2:%@", path2);
path2:/Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830/Library/Caches
3、
NSString *path3 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSLog(@"path3:%@", path3);
path3:/Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830/Documents
4、
NSString *path4 = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSLog(@"path4:%@", path4);
path4:/Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830/Documents
5、
NSString *path5 = [NSHomeDirectory() stringByAppendingPathComponent:@"Library"];
NSLog(@"path5:%@", path5);
path5:/Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830/Library
6、
NSString *path6 = [NSHomeDirectory() stringByAppendingPathComponent:@"temp"];
NSLog(@"path6:%@", path6);
path6:/Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830/temp