【问题标题】:How to access images stored in Documents Directory in ios8如何在 ios8 中访问存储在 Documents 目录中的图像
【发布时间】:2014-11-15 13:04:07
【问题描述】:
【问题讨论】:
标签:
directory
ios8
xcode6
documentsdirectory
【解决方案1】:
好像你正在存储完整的路径。
在 IOS 8 中,Apple 更改了目录结构。Apple 在内部扩展了文档目录中的文件夹(即类似于 /developer/data/一些随机数序列)。目录文件夹在每次构建时都会不断变化,如果您将完整路径存储在您的 sqlite 那么您在该位置找不到任何文件,因为文档目录位置已更改。
解决方案是不存储完整路径,只将文档目录的路径存储到数据库中,访问图片时只需在当前应用程序文档目录前加上前缀,然后您就可以从您的应用程序目录访问您的图片
例子:
//Storing Images
NSString *imagePathString = [NSString stringWithFormat:@“/%@/%@.png”,@“Your Folder name”,@“image name”];
//Store this image path String to database
//Retrieving Images
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:imagePathString];
//This is the path for your images