2016-08-03 88 views
1

实际上,我依靠安全选项的完整文件路径(为此,我需要将文件路径存储在钥匙串中)。这意味着当我重建应用程序(或者当它发布到AppStore时会得到更新)时,由于文件路径中的包ID更改,这些功能被破坏。从文档目录获取文件路径 - Objective-c iOS

我想过这个问题的解决方案:只从文档目录获取文件路径(/Documents/.../.../myFile.pdf)而不是完整路径(/ var/mobile/.. 。/ ...)。有没有办法做到这一点?

或者有任何其他解决方案,我的问题?

在此先感谢!

+1

用得到它'的NSArray *路径= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);'并保存后,只有什么。 – Larme

+0

检查我的答案 – user3182143

回答

0

感谢@Larme和@ user3182143,我已经找到了解决办法:获得文件的路径和分裂文件路径2:文档目录前一个部分

bundlePath = [documentsDirectory stringByDeletingLastPathComponent]; 

,另一部分与

documentsPath = [documentsDirectory lastPathComponent]; 
... 
filepath = [documentsPath stringByApendingPathComponent:@"myFile.pdf"]; 

如果我需要完整的路径,我“会通过

fullPath = [bundlePath stringByAppendingPathComponent:filepath]; 
1

从文件目录中获取文件路径

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *getPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",strFileName]]; 
相关问题