1. App Home(/AppBane,aoo)。包含App bundle的目錄,不要在該路徑下寫任何檔案。
2. /Documents/。使用該路徑放置關鍵資料,也就是不能通過App重新生成的資料。該路徑可通過配置實作iTunes共享檔案。可被iTunes備份。(現在儲存在該路徑下的檔案還需要考慮iCloud同步)
3. /Library/。該路徑下一般儲存着使用者配置檔案。可建立子檔案夾。可以用來放置您希望被備份但不希望被使用者看到的資料。該路徑下的檔案夾,除Caches以外,都會被iTunes備份。
4. /tmp/。使用該路徑儲存臨時檔案。App應該删除那些不再被使用的檔案,系統也會在App關閉後删除殘留檔案。該路徑下的檔案不會被iTunes備份。
代碼如下:
//程式所在目錄
NSString *path1=NSHomeDirectory();
NSLog(@"path1 is %@\n\n\n",path1);
Users/huangbaoxian/Library/Application Support/iPhone Simulator/7.1/Applications/8A0D16B8-041F-4BA0-8823-77D7B52E6753
//緩存目錄Library/Caches
NSString *path2=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSLog(@" path2 %@\n\n\n",path2);
///Users/huangbaoxian/Library/Application Support/iPhone Simulator/7.1/Applications/8A0D16B8-041F-4BA0-8823-77D7B52E6753/Library/Caches
NSString *path3=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSLog(@"path3 is %@\n\n\n",path3);
//Users/huangbaoxian/Library/Application Support/iPhone Simulator/7.1/Applications/8A0D16B8-041F-4BA0-8823-77D7B52E6753/Documents
//拼接路徑
NSString *path4=[NSHomeDirectory() stringByAppendingPathComponent: @"Documents"];
NSLog(@"path4 is %@\n\n\n",path4);
//Users/huangbaoxian/Library/Application Support/iPhone Simulator/7.1/Applications/8A0D16B8-041F-4BA0-8823-77D7B52E6753/Documents
NSString *path5 = [NSHomeDirectory() stringByAppendingPathComponent:@"Library"];
NSLog(@"path5 is %@\n\n\n", path5);
///Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830/Library
NSString *path6 = [NSHomeDirectory() stringByAppendingPathComponent:@"temp"];
NSLog(@"path6 is :%@\n\n\n", path6);
///Users/yuanjun/Library/Application Support/iPhone Simulator/4.2/Applications/172DB70A-145B-4575-A31E-D501AC6EA830/temp