开发者

Launch application from application bundle

I have a helper application, which is within my main application's application bundle (in the Resources). I'm not sure how to get the path of the application from ins开发者_JS百科ide the bundle and launch it.


I'm not sure I fully understand the question. I think you're saying you have an application (let's call it PrimaryApplication.app) and inside it's Resources directory there is an application you need to launch (let's call it Helper.app). In that case you use NSBundle's -bundlePath to get the path to the currently running application, then you append the path to your helper from there. You can use NSWorkspace to launch the application once you know the path to it.

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *helperAppPath = [[mainBundle bundlePath]
  stringByAppendingString:@"/Contents/Resources/Helper.app"];

[[NSWorkspace sharedWorkspace] launchApplication:helperAppPath];


In Core Foundation, CFBundleCopyResourceURL should get you the application's url.

In Cocoa, NSBundle has equivalent pathForResource:ofType: and URLForResource:withExtension: methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜