简体   繁体   中英

XCode - file not found in document directory

I am having random error while reading saved photos from document directory in iPhone. I save photos taken from my app to document directory and then read it from there next time when user come back. However, after XCode 6 & base SDK change to 8.1, this document directory path keeps changing. So sometime I found photos and sometime not.

I read few posts online thats says that not Apple differentiate App from Data and that's why this issue coming up. Anyone has any thoughts on this? Any solution?

This is how I save file to document Directory

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path firstObject];
NSString *filePath = [documentDirectory stringByAppendingPathComponent:@"key"];
[image writeToFile:path atomically:YES];

And this is how I read it:

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path firstObject];
NSString *filePath = [documentDirectory stringByAppendingPathComponent:@"key"];
UIImage *cellImage = [[UIImage alloc] initWithContentsOfFile:filePath];

转到产品-方案-编辑方案-选项-工作目录并指定工作目录

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