【问题标题】:How to access images stored in Documents Directory in ios8如何在 ios8 中访问存储在 Documents 目录中的图像
【发布时间】:2014-11-15 13:04:07
【问题描述】:

在 ios7 中,我们可以将图像写入文档目录并毫无问题地访问它。 在 IOs8 中,我能够将图像数据写入文档目录并访问它。每次我在模拟器上运行应用程序时,图像文件夹的位置都会发生变化。我经历了许多堆栈溢出问题和苹果的技术说明(链接:https://developer.apple.com/library/ios/technotes/tn2406/_index.html)但我没有得到任何解决方案。实际上我正在存储路径sqlite 数据库中的图像文件。

任何帮助表示赞赏。

【问题讨论】:

    标签: 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
    

    【讨论】:

    • 哇!只是完美的答案。你让我的问题消失了! :)
    猜你喜欢
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    相关资源
    最近更新 更多