//主目录,方法一 NSString *path = NSHomeDirectory(); NSLog(@"NSHomeDirectory:%@",path); //主目录,方法二 NSString *userName = NSUserName(); NSString *rootPath = NSHomeDirectoryForUser(userName); NSLog(@"NSHomeDirectoryForUser:%@",rootPath); //Documents目录 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory=[paths objectAtIndex:0]; NSLog(@"NSDocumentDirectory:%@",documentsDirectory);
打印:
2015-10-03 19:45:27.194 视频[17571:1226155] NSHomeDirectory:/Users/Eazy/Library/Developer/CoreSimulator/Devices/46073ABC-2125-4809-8920-B94B59020799/data/Containers/Data/Application/A0A2182E-D2EE-4C09-BE97-D73E100D252B
2015-10-03 19:45:27.195 视频[17571:1226155] NSHomeDirectoryForUser:/Users/Eazy/Library/Developer/CoreSimulator/Devices/46073ABC-2125-4809-8920-B94B59020799/data/Containers/Data/Application/A0A2182E-D2EE-4C09-BE97-D73E100D252B
2015-10-03 19:45:27.195 视频[17571:1226155] NSDocumentDirectory:/Users/Eazy/Library/Developer/CoreSimulator/Devices/46073ABC-2125-4809-8920-B94B59020799/data/Containers/Data/Application/A0A2182E-D2EE-4C09-BE97-D73E100D252B/Documents
分析:
模拟器UDID:46073ABC-2125-4809-8920-B94B59020799
应用程序UDID:A0A2182E-D2EE-4C09-BE97-D73E100D252B
前往该沙盒路径:
Documents:应用主要数据存放在此,itunes会备份
Library/Caches:缓存文件,应用退出不会删除,iTunes不会备份此目录
Library/Preferences:程序偏好设置文件,itunes会备份
tmp:存放临时文件,内存不足时会不定时删除,不建议存放长时间使用的文件,iTunes不会备份此目录