如何在 Macintosh 中以编程方式退出应用程序

发布于 2024-12-02 20:36:08 字数 272 浏览 5 评论 0原文

我需要从另一个应用程序退出一个应用程序。我知道如何从我的应用程序中打开另一个应用程序,但我不知道如何退出它。

要打开其他应用程序:

 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 技术交流群。

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

发布评论

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

评论(2

只是偏爱你 2024-12-09 20:36:08

您正在启动该应用程序还是它已经在运行?

如果您自己启动它,则可以使用 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

爱情眠于流年 2024-12-09 20:36:08

根据文档,看起来不支持此功能;只有一个函数可以关闭应用程序,并且该函数已被弃用。也许您可以向您的应用程序发送一条消息,让您的应用程序可以自行解释并终止自身?

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?

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