我尝试将相对路径(例如 subFolder/file
)作为参数传递给我的应用程序。子文件夹位于复制 bundle 资源中,我确保该文件夹位于 myApp.app/Contents/下。
我在“方案”>“运行”>“参数”>“启动时传递的参数”中添加了一个参数,如下所示
子文件夹/文件
。
但是,运行应用程序时,调试器输出显示:
/var/mobile/applications/feae1664-6f16-4b96-8b8d-05b4531fe6da/myApp.app/myappbin: cannot open subFolder/file: No such file or directory
myappbin
是应用程序包的可执行文件。
我应该如何指定这样的相对路径?
编辑
问题是我的应用程序确实需要使用该路径作为运行时变量,以进行测试。我确实知道如何在 ObjC 中引用 mainBundle 中的 bundle 文件夹/文件。
最佳答案
您不需要将路径作为参数传递。您只需要使用 NSBundle 方法返回路径即可。
看看
[[NSBundle mainBundle] pathForResouce: ofType:];
还有 NSBundle 的文档, https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html
关于ios - 如何在方案中将相对路径(相对于主包)传递给 iOS 应用程序作为 "argument passed on launch"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17663380/