开发者

How to hide window of UIAgent process with cocoa

I have an UIAgent application with one window. I want to hide/show it from another application.How do I do it with cocoa? Seems like hide/unhide met开发者_如何转开发hods of NSRunningApplication doesn't affect UIAgent processes.

Thanks in advance


I solved it with NSDistributionNotifications. In the UIAgent application I add an observer to a @"QuitProcessNotification" (any other name):

[[NSDistributedNotificationCenter defaultCenter]
                             addObserver:self selector:@selector(quit:) 
                             name:@"QuitProcessNotification" 
                             object:@"com.MyCompany.MyApp" 
                             suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];

The callback looks like that:

- (void) quit:(NSNotification *) notification
{
    [NSApp terminate:nil];
}

In the main application: Sending notification:

[[NSDistributedNotificationCenter defaultCenter]
                     postNotificationName:@"QuitProcessNotification" 
                     object:@"com.MyCompany.MyApp"
                     userInfo: nil /* no dictionary */
                     deliverImmediately: YES];

Be sure, that the object parameter is indeed your sender application's bundle identifier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜