可可成分的透明流程创建

发布于 2024-08-10 23:52:38 字数 263 浏览 2 评论 0原文

我有一个应用程序A,它可能需要也可能不需要生成应用程序B,并将使用远程消息传递(通过NSConnection等)与其进行通信.)。

虽然我知道如果首先启动 B 如何执行此操作,但我想知道:
什么是基于清洁可可的透明按需启动 B 的方法?

(对于那些熟悉 COM 的人来说,我正在有效地寻找 CoCreateInstance() 等效项)

I have an application A which may or may not need to spawn an application B and will communicate with it using remote messaging (via NSConnections etc.).

While i know how to do this if B is started first, i wonder:
What is a clean cocoa-based approach of transparently starting B on demand?

(For those familiar with COM, i am effectively looking for a CoCreateInstance() equivalent)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

始终不够 2024-08-17 23:52:38

如果这是一个 GUI 应用程序,您可以为 10.6 执行以下操作:

NSArray * runningBs = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.example.B"];
if ([runningBs count] == 0) {
  NSURL * bURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.example.B"];
  NSRunningApplication * b = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:bURL options:NSWorkspaceLaunchDefault configuration:nil error:nil];
}

对于 10.5:
使用 -[NSWorkspace launchApplications] 并迭代数组以查看是否找到 B
如果没有,请找到 [NSWorkspace AbsolutePathForAppBundleWithIdentifier:],然后使用 [NSWorkspace launchApplication:] 变体之一。

If this is a GUI app, you could do something like this for 10.6:

NSArray * runningBs = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.example.B"];
if ([runningBs count] == 0) {
  NSURL * bURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.example.B"];
  NSRunningApplication * b = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:bURL options:NSWorkspaceLaunchDefault configuration:nil error:nil];
}

For 10.5:
Use -[NSWorkspace launchedApplications] and iterate through the array to see if you find B.
If you don't, find the [NSWorkspace absolutePathForAppBundleWithIdentifier:] and then use one of the [NSWorkspace launchApplication:] varieties.

单身狗的梦 2024-08-17 23:52:38

如果另一个应用程序是命令行应用程序或可以像命令行应用程序一样运行,则 NSTask 是最佳选择 - 您可以启动另一个程序并定义其标准输入、输出和错误流。如果这是一个 GUI 应用程序,您可以使用 Scripting Bridge 或 NSWorkspace + 使用您自己的 NSConnection 通信协议等。

If the other application is a command-line app or can behave like one, NSTask is the best choice — you can launch another program and define its standard input, output and error streams. If this is a GUI app, you can use Scripting Bridge or NSWorkspace + use your own communication protocol with NSConnection, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文