NSSearchPathDirectory
这些常量指定各种目录的位置。
enum {
NSApplicationDirectory = 1,
NSDemoApplicationDirectory,
NSDeveloperApplicationDirectory,
NSAdminApplicationDirectory,
NSLibraryDirectory,
NSDeveloperDirectory,
NSUserDirectory,
NSDocumentationDirectory,
NSDocumentDirectory,
NSCoreServiceDirectory,
NSAutosavedInformationDirectory = 11,
NSDesktopDirectory = 12,
NSCachesDirectory = 13,
NSApplicationSupportDirectory = 14,
NSDownloadsDirectory = 15,
NSInputMethodsDirectory = 16,
NSMoviesDirectory = 17,
NSMusicDirectory = 18,
NSPicturesDirectory = 19,
NSPrinterDescriptionDirectory = 20,
NSSharedPublicDirectory = 21,
NSPreferencePanesDirectory = 22,
NSItemReplacementDirectory = 99,
NSAllApplicationsDirectory = 100,
NSAllLibrariesDirectory = 101
};
typedef NSUInteger NSSearchPathDirectory;
在这些路径目录中,我知道NSCachesDirectory和NSDocumentDirectory在iOS中可用。你知道其他人是否也是吗?
目前我正在NSCachesDirectory中下载图像,我使用[UIImage imageNamed:]在屏幕上打印图片。但我正在寻找一个更明确的文件夹来存储我的图像。
谢谢,
答案 0 :(得分:11)
据我所知,这些只适用于iOS:
NSDocumentDirectory is Documents/ (persistent, backed up, may be visible in iTunes)
NSLibraryDirectory is Library/ (persistent, backed up, not visibe to the user)
NSCachesDirectory is Library/Caches/ (not backed up, may be cleared by system)
此外,还有:
NSTemporaryDirectory() is tmp/ (not backed up, *will* be cleared by system)
所有路径都与应用程序沙箱目录相关,您应该能够写入所有路径。所有这些目录都有不同的行为,适用于不同类型的文件。
为了存储图像,我会在库中创建目录,比方说Library/Thumbnails/
。如果图像易于恢复或可下载,则应创建并使用Library/Caches/Thumbnails/
。