如何将相对路径(相对于主bundle)作为方案中的"argument passed on launch"传递给iOS应用程序?



我尝试将一个相对路径(例如subFolder/file)作为参数传递给我的应用程序。子文件夹位于Copy Bundle Resources中,我确保该文件夹位于myApp.app/Contents/下。我在Scheme>Run>Arguments>ArgumentsPassed On Launch中添加了一个参数,作为CCD_ 2。

然而,当运行应用程序时,调试器输出显示:

/var/mobile/applications/feae1664-6f16-4b96-8b8d-05b4531fe6da/myApp.app/myappbin: cannot open subFolder/file: No such file or directory

myappbin是应用程序捆绑包的可执行文件。

我应该如何指定这样的相对路径?

编辑

问题是,出于测试目的,我的应用程序确实需要将该路径用作运行时变量。我知道如何在ObjC中引用mainBundle中的捆绑文件夹/文件。

您不需要将路径作为参数传入。您只需要使用NSBundle方法来返回路径。

看看

[[NSBundle mainBundle] pathForResouce: ofType:];

还有NSBundle的文档,https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html

最新更新