简体   繁体   中英

How to access images stored in Documents Directory in ios8

In ios7 we can write images to documents directory and access it without any problem. In IOs8 i am able to write imagesdata to documents directory and access it. The location of images folder changes every time i run the app on the Simulator.I went through many stack overflow questions and apple's Technical Note (link: https://developer.apple.com/library/ios/technotes/tn2406/_index.html ) but i didn't get any solution.Actually i am storing the path of images file in sqlite database.

Any help appreciated.

Seems like you are storing the complete path.

In IOS 8 Apple changed the directory structure.Apple extended folders in documents directory internally(ie something like /developer/data/some random number sequence).Directory folders keeps on changing on every build,if u store the complete path in your sqlite then you do not find any file at the location because the documents directory location has changed.

The solution is do not store the complete path just store the path from documents directory into the database,while accessing images just prefix it with current application documents directory, then you are able to access your images from your apps directory

Example:

//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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM