开发者

NSTask setLaunchPath Objective-C Cocca

This is a very simple question. I have a script in the same folder as the 开发者_开发知识库Cocoa app. I can't seem to set the path to it properly for setLaunchPath for NSTask. Help please.

I have a folder called Project. Inside of it, exist multiple folders but only two we care about: Classes (the source files for the Cocoa app are here) and Ruby (which is a ruby server folder). I am trying to call Ruby/script/server. I assumed it would be something like ./Ruby/script/server or Ruby/script/server but both are wrong.

Thanks.

EDIT: I guess what I'm actually asking is if there is a way to access the folder where the source files or the project is by using a special character or shortcut because by default it goes to the /tmp folder.


The current directory (in the unix sense) in an app is not guaranteed to be anything. The path to the app itself can be obtained by getting the main app bundle by

NSBundle*mainBundle=[NSBundle mainBundle];

and then getting its path

NSString*path=[mainBundle bundlePath];

However please don't do that; you won't be able to distribute your app without extra instructions of putting files here and there. Instead, put your Ruby code inside yourApp.app/Contents/Resources/. This can be done by including the Ruby code in the XCode, and making sure it's set to be copied into the app. The files inside this Resources directory can be obtained as follows:

NSString*path=[mainBundle pathForResource:@"rubyServer" ofType:@"rb"];

To learn more about the bundle structure, read Bundle Programming Guide.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜