如何在 Macintosh 中以编程方式退出应用程序
我需要从另一个应用程序退出一个应用程序。我知道如何从我的应用程序中打开另一个应用程序,但我不知道如何退出它。
要打开其他应用程序:
CFURLRef mtURL = CFURLCreateWithString(kCFAllocatorDefault,CFSTR("TestApplication:"), NULL);
LSOpenCFURLRef(mtURL,nil);
任何人都可以对此提出建议吗?
谢谢你, 钱德拉。
I need to quit an application from another application. I know how to open another application from my application but I don't know how to quit it.
To Open other app:
CFURLRef mtURL = CFURLCreateWithString(kCFAllocatorDefault,CFSTR("TestApplication:"), NULL);
LSOpenCFURLRef(mtURL,nil);
Can any one please suggest on this?
Thank you,
Chandra.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在启动该应用程序还是它已经在运行?
如果您自己启动它,则可以使用 NSTask,而不是使用 URL 方法,这样您可以更好地控制执行。
NSTask 有一条可以发送的终止消息。
请参阅此页面的一些示例: http://www.cocoadev.com/index.pl?NSTask
另请参阅这个问题:如何终止进程(非自身)在 Cocoa 应用程序内
Are you launching that app or is it already running?
If you are launching it yourself, instead of using your URL method, you could use a NSTask, that would give you more control on the exectution.
NSTask has a terminate message you can send.
See this page for some examples: http://www.cocoadev.com/index.pl?NSTask
Also see this SO question: How to terminate a process (not self) from inside a Cocoa application
根据文档,看起来不支持此功能;只有一个函数可以关闭应用程序,并且该函数已被弃用。也许您可以向您的应用程序发送一条消息,让您的应用程序可以自行解释并终止自身?
According to the documentation, it doesn't look like this is supported; there is only one function to close the application, and that function is deprecated. Perhaps you could send your application a message that your application could interpret and kill itself of its own volition?