This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
library:ios:appfolder [2022/12/10 10:12] lhaosen [4. 沙盒主目录路径] |
library:ios:appfolder [2022/12/30 18:33] (current) lhaosen [1. 文档目录 Documents] |
||
---|---|---|---|
Line 12: | Line 12: | ||
===== - 文档目录 Documents ===== | ===== - 文档目录 Documents ===== | ||
- | 有关应用的所有数据文件应该写入到这个目录下,这个目录用于存储用户数据或者其他应该定期备份的信息。 | + | iPhone会为每一个应用程序生成一个私有目录,这个目录位于: |
+ | / | ||
+ | 并随即生成一个数字字母串作为目录名,在每一次应用程序启动时,这个字母数字串都是不同于上一次。有关应用的所有数据文件应该写入到这个目录下,这个目录用于存储用户数据或者其他应该定期备份的信息。 | ||
* 获取Documents目录路径的方法 | * 获取Documents目录路径的方法 | ||
- | NSString*documentPath | + | NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, |
+ | |||
+ | // Swift | ||
+ | let ducumentPath = NSHomeDirectory() + "/ | ||
+ | | ||
* 注: | * 注: | ||
+ | |||
上面NSDocumentDirectory参数一位置:directory为获取哪个文件夹 | 上面NSDocumentDirectory参数一位置:directory为获取哪个文件夹 | ||
- | |||
NSUserDomainMask 参数二位置:domainMask为在哪个范围内搜索,NSUserDomainMask 表示在用户的手机上查找 | NSUserDomainMask 参数二位置:domainMask为在哪个范围内搜索,NSUserDomainMask 表示在用户的手机上查找 | ||
- | |||
YES 参数三位置:expandTilde为是否展开全路径。YES:表示展开全路径;NO:不会展开全路径,会把应用沙盒的路径用波浪号(~)代替 | YES 参数三位置:expandTilde为是否展开全路径。YES:表示展开全路径;NO:不会展开全路径,会把应用沙盒的路径用波浪号(~)代替 | ||
Line 33: | Line 38: | ||
缓存目录。用于存储应用程序专用的支持文件,保存应用程序再次启动过程中需要的信息。iTunes不会同步此文件夹,适合存储体积大,不需要备份的非重要数据。 | 缓存目录。用于存储应用程序专用的支持文件,保存应用程序再次启动过程中需要的信息。iTunes不会同步此文件夹,适合存储体积大,不需要备份的非重要数据。 | ||
- | NSString | + | NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, |
* Perferences目录: | * Perferences目录: | ||
Line 49: | Line 53: | ||
===== - 临时文件夹 tmp ===== | ===== - 临时文件夹 tmp ===== | ||
- | |||
iTunes不会同步此文件夹,里面存的是临时文件,随时可以被删除,一般不怎么用 | iTunes不会同步此文件夹,里面存的是临时文件,随时可以被删除,一般不怎么用 | ||
- | | + | |
- | NSString | + | NSString *tmppath = NSTemporaryDirectory(); |
===== - 沙盒主目录路径 ===== | ===== - 沙盒主目录路径 ===== | ||
+ | |||
NSString* homePaht = NSHomeDirectory(); | NSString* homePaht = NSHomeDirectory(); | ||
+ | | ||
+ | | ||
+ | | ||
+ | NSSearchPathForDirectori esInDomains(“想要查找的目录”,“想要从哪个路径区域保护区查找”) | ||
+ | 查找的区域: | ||
+ | typedef NS_OPTIONS(NSUInteger, | ||
+ | NSUserDomainMask =1, // 用户的主目录 | ||
+ | NSLocalDomainMask =2, // 当前机器的本地目录 | ||
+ | NSNetworkDomainMask =4, // | ||
+ | NSSystemDomainMask =8, // 被苹果系统提供的,不可更改的位置 (/ | ||
+ | NSAllDomainsMask = 0x0ffff | ||
+ | }; | ||
+ | 想要查找的目录: | ||
+ | NSApplicationDirectory =1, // 到applications (Applications)目录下 | ||
+ | NSDemoApplicationDirecto ry, // 到Applications/ | ||
+ | NSDeveloperApplicationDi rectory, | ||
+ | NSAdminApplicationDirect ory, // 到Applications/ | ||
+ | NSLibraryDirectory, | ||
+ | NSDeveloperDirectory, | ||
+ | NSUserDirectory, | ||
+ | NSDocumentationDirectory , // 到documentation (Documentation)的目录下 | ||
+ | NSDocumentDirectory, | ||
+ | NSCoreServiceDirectory, | ||
+ | NSAutosavedInformationDi rectory NS_ENUM_AVAILABLE(10_6, | ||
+ | NSDesktopDirectory =12, // 本地用户的桌面 | ||
+ | NSCachesDirectory =13, // 本地缓冲区目录(Library/ | ||
+ | NSApplicationSupportDire ctory =14, // 本地应用支持文件目录 (plug-ins, etc) (Library/ | ||
+ | NSDownloadsDirectory NS_ENUM_AVAILABLE(10_5, | ||
+ | NSInputMethodsDirectory NS_ENUM_AVAILABLE(10_6, | ||
+ | NSMoviesDirectory NS_ENUM_AVAILABLE(10_6, | ||
+ | NSMusicDirectory NS_ENUM_AVAILABLE(10_6, | ||
+ | NSPicturesDirectory NS_ENUM_AVAILABLE(10_6, | ||
+ | NSPrinterDescriptionDire ctory NS_ENUM_AVAILABLE(10_6, | ||
+ | NSSharedPublicDirectory NS_ENUM_AVAILABLE(10_6, | ||
+ | NSPreferencePanesDirecto ry NS_ENUM_AVAILABLE(10_6, | ||
+ | NSApplicationScriptsDire ctory NS_ENUM_AVAILABLE(10_8, | ||
+ | NSItemReplacementDirecto ry NS_ENUM_AVAILABLE(10_6, | ||
+ | NSAllApplicationsDirecto ry =100, // 应用能够发生的所有路径 | ||
+ | NSAllLibrariesDirectory =101, // | ||
+ | NSTrashDirectory NS_ENUM_AVAILABLE(10_8, | ||
+ | }; | ||
+ |