简体   繁体   English

XCode-在文档目录中找不到文件

[英]XCode - file not found in document directory

I am having random error while reading saved photos from document directory in iPhone. 从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. 但是,在XCode 6和基本SDK更改为8.1之后,此文档目录路径会不断更改。 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. 我在线上读过几篇文章,这表示Apple无法将App与Data区别开来,这就是为什么出现此问题的原因。 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];

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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