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:19] lhaosen [1. 文档目录 Documents] |
library:ios:appfolder [2022/12/30 18:33] (current) lhaosen [1. 文档目录 Documents] |
||
---|---|---|---|
Line 12: | Line 12: | ||
===== - 文档目录 Documents ===== | ===== - 文档目录 Documents ===== | ||
- | 有关应用的所有数据文件应该写入到这个目录下,这个目录用于存储用户数据或者其他应该定期备份的信息。 | + | iPhone会为每一个应用程序生成一个私有目录,这个目录位于: |
+ | / | ||
+ | 并随即生成一个数字字母串作为目录名,在每一次应用程序启动时,这个字母数字串都是不同于上一次。有关应用的所有数据文件应该写入到这个目录下,这个目录用于存储用户数据或者其他应该定期备份的信息。 | ||
* 获取Documents目录路径的方法 | * 获取Documents目录路径的方法 | ||
NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, | NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, | ||
+ | | ||
+ | // Swift | ||
+ | let ducumentPath = NSHomeDirectory() + "/ | ||
+ | | ||
* 注: | * 注: | ||
- | * | + | |
上面NSDocumentDirectory参数一位置:directory为获取哪个文件夹 | 上面NSDocumentDirectory参数一位置:directory为获取哪个文件夹 | ||
NSUserDomainMask 参数二位置:domainMask为在哪个范围内搜索,NSUserDomainMask 表示在用户的手机上查找 | NSUserDomainMask 参数二位置:domainMask为在哪个范围内搜索,NSUserDomainMask 表示在用户的手机上查找 | ||
Line 56: | Line 62: | ||
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, | ||
+ | }; | ||
+ |