开发者

Why currentDirectoryPath return different result under IDE and without it?

I have a strange trouble using below code

NSString * pth = [[[NSFileManager defaultManager] currentDirectoryPath] copy];

If that code runs un开发者_开发知识库der IDE it works fine, and i have pth like that

/Users/user/Desktop/iShutdown/build/Release

But if i run that code without IDE simply launching my standalone app i see in log that pth is only contains "/"

Why? how to get same result in standalone mode?


The initial working directory will depend on how the application is launched and you should never make any assumptions about what this will be. For Finder launches it will typically be / as you have seen, while for Xcode launches it will usually be the same directory as the executable (although you can change this in the settings for the executable). There are various other ways of launching an app though, e.g. from the command line, so the initial working directory can be pretty much anything the user wants it to be.

If you just want to find some specific file which resides at a specific location relative to your app, e.g. a data file that your app needs, then you should just get the path to your application bundle and use that, not the working directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜