在Foundation Constants Reference中是什么
NSMoviesDirectory
NSMusicDirectory
NSPicturesDirectory
如果我正在处理图像,我应该存储在NSPicturesDirectory
?
答案 0 :(得分:2)
NSSearchPathDirectory
枚举定义了应存储特定类型文件的文件夹位置
想法是这些位置确定用户EXPECTS寻找应用程序/文档/图片/电影的路径......
e.g。
typedef NS_ENUM(NSUInteger, NSSearchPathDirectory) {
NSApplicationDirectory = 1, // supported applications (Applications)
...
NSLibraryDirectory, // various documentation, support, and configuration files, resources (Library)
NSDocumentationDirectory, // documentation (Documentation)
NSDocumentDirectory, // documents (Documents)
...
NSDesktopDirectory = 12, // location of user's desktop
...
NSMoviesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 17, // location of user's Movies directory (~/Movies)
NSMusicDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 18, // location of user's Music directory (~/Music)
NSPicturesDirectory NS_ENUM_AVAILABLE(10_6, 4_0) = 19, // location of user's Pictures directory (~/Pictures)
...
NSTrashDirectory NS_ENUM_AVAILABLE(10_8, NA) = 102 // location of Trash directory
};
现在......真实位置(文件路径)取决于您的应用存储位置
因为在IOS中没有用户可见的文件系统,特别是因为每个应用程序都在自己的沙箱中运行,所以它们的用途有限:
他们只告诉操作系统在哪里找到什么,然后可以假设如何处理这些位置:缓存可以随意丢弃,必须保留文档...电影/图片
请记住,虽然IOS只看到缓存/其他任何内容,但OSX肯定会以不同的方式处理路径
答案 1 :(得分:1)
您可以将图像保存到文档目录或tmp目录,以获取可以使用以下内容的文档目录。
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* dd = [paths objectAtIndex:0]; //document directory path
默认情况下"电影","音乐"和"图片"不在目录中。您必须创建路径并放置数据文件。
例如:NSMoviesDirectory
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSMoviesDirectory,NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSError * error;
if (![[NSFileManager defaultManager] fileExistsAtPath: documentsDirectory])
{
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:NO attributes:nil error:&error];
NSString * resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sleep.mp4"];
[[NSFileManager defaultManager] copyItemAtPath:resourceDBFolderPath toPath:[documentsDirectory stringByAppendingPathComponent:@"sleep.mp4"] error:&error];
}
else
{
NSString * resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sleep.mp4"];
[[NSFileManager defaultManager] copyItemAtPath:resourceDBFolderPath toPath: [documentsDirectory stringByAppendingPathComponent:@"sleep.mp4"] error:&error];
}