好记性不如烂笔头。记一笔:
1 //获取沙盒主目录路径 2 NSString *homeDir = NSHomeDirectory(); 3 NSLog(@"Home: %@", homeDir); 4 5 // 获取Documents目录路径 6 NSArray *path1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 7 NSString *docDir = [path1 firstObject]; 8 NSLog(@"Documents: %@", docDir); 9 10 // 获取Caches目录路径 11 NSArray *path2 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 12 NSString *cachesDir = [path2 firstObject]; 13 NSLog(@"Caches: %@", cachesDir); 14 15 // 获取tmp目录路径 16 NSString *tmpDir = NSTemporaryDirectory(); 17 NSLog(@"tmp: %@", tmpDir);
输出:
Home: /Users/abcd/Library/Developer/CoreSimulator/Devices/C59612C1-025A-422C-BC37-7195064B5CD1/data/Containers/Data/Application/EEEAC0B9-A09E-4C99-81AC-81583DBC07C5
Documents: /Users/abcd/Library/Developer/CoreSimulator/Devices/C59612C1-025A-422C-BC37-7195064B5CD1/data/Containers/Data/Application/EEEAC0B9-A09E-4C99-81AC-81583DBC07C5/Documents
Caches: /Users/abcd/Library/Developer/CoreSimulator/Devices/C59612C1-025A-422C-BC37-7195064B5CD1/data/Containers/Data/Application/EEEAC0B9-A09E-4C99-81AC-81583DBC07C5/Library/Caches
tmp: /Users/abcd/Library/Developer/CoreSimulator/Devices/C59612C1-025A-422C-BC37-7195064B5CD1/data/Containers/Data/Application/EEEAC0B9-A09E-4C99-81AC-81583DBC07C5/tmp/