我有一个带有一个窗口的UIAgent
应用程序。我想隐藏/从另一个应用程序中显示它。如何用可可做到这一点?似乎hide
的{{1}} / unhide
方法不会影响UIAgent流程。
提前致谢
答案 0 :(得分:1)
我用NSDistributionNotifications
解决了这个问题。在UIAgent应用程序中,我将观察者添加到@"QuitProcessNotification"
(任何其他名称):
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self selector:@selector(quit:)
name:@"QuitProcessNotification"
object:@"com.MyCompany.MyApp"
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
回调看起来像是:
- (void) quit:(NSNotification *) notification
{
[NSApp terminate:nil];
}
在主要应用中: 发送通知:
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"QuitProcessNotification"
object:@"com.MyCompany.MyApp"
userInfo: nil /* no dictionary */
deliverImmediately: YES];
请确保object
参数确实是您的发件人应用程序的包标识符。