可可成分的透明流程创建
我有一个应用程序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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是一个 GUI 应用程序,您可以为 10.6 执行以下操作:
对于 10.5:
使用
-[NSWorkspace launchApplications]
并迭代数组以查看是否找到 B。如果没有,请找到
[NSWorkspace AbsolutePathForAppBundleWithIdentifier:]
,然后使用[NSWorkspace launchApplication:]
变体之一。If this is a GUI app, you could do something like this for 10.6:
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.如果另一个应用程序是命令行应用程序或可以像命令行应用程序一样运行,则 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.