[英]Get file path from Document directory - Objective-c iOS
实际上,我依赖于完整的文件路径来获取安全选项(因为我需要将文件路径存储在钥匙串中)。 这意味着当我重建应用程序时(或者在发布到AppStore时它将获得更新),由于文件路径中的包ID更改,这些功能会被破坏。
我想到了这个问题的解决方案:只从Documents目录(/Documents /.../.../myFile.pdf)获取文件路径而不是完整路径(/var/mobile/.../ .. )。 有办法做到这一点吗?
或者,我的问题还有其他解决办法吗?
提前致谢 !
从文档目录中获取文件路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",strFileName]];
感谢@Larme和@ user3182143,我找到了一个解决方案:获取文档路径并将文件路径拆分为2:文档目录之前的一部分
bundlePath = [documentsDirectory stringByDeletingLastPathComponent];
和另一部分
documentsPath = [documentsDirectory lastPathComponent];
...
filepath = [documentsPath stringByApendingPathComponent:@"myFile.pdf"];
如果我需要完整的路径,我会得到它
fullPath = [bundlePath stringByAppendingPathComponent:filepath];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.