[英]One Cocoa app notified when another cocoa app terminated
Suppose there are two cocoa apps APP1 and APP2. 假设有两个可可应用程序APP1和APP2。 I want APP2 to be notified when APP1 terminates. 我希望在APP1终止时通知APP2。 I want some callback function registered with APP2 which will be called as soon as APP1 terminates. 我想要一些在APP2注册的回调函数,一旦APP1终止就会调用它。 How can I achieve this? 我怎样才能做到这一点? Any sample code will be highly appreciated. 任何示例代码都将受到高度赞赏。
You can observe the NSWorkspaceDidTerminateApplicationNotification
. 您可以观察NSWorkspaceDidTerminateApplicationNotification
。 Its userInfo
dictionary contains details about which application was terminated (an NSRunningApplication
object). 其userInfo
字典包含有关终止哪个应用程序的详细信息( NSRunningApplication
对象)。
You certainly looking for NSDistributedNotificationCenter . 您当然在寻找NSDistributedNotificationCenter 。
Whenever you want to send a notification from One app to Other, just like XCode3.2 and Interface Builder were sending notifications, use NSDistributedNotificationCenter . 每当您想要从One应用程序向其他应用程序发送通知时,就像XCode3.2和Interface Builder正在发送通知一样,请使用NSDistributedNotificationCenter 。
This documentation contains sample code such as DockTile, that will come handy to you. 本文档包含DockTile等示例代码,对您来说非常方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.