开发者

How to hide window of UIAgent process with cocoa

开发者 https://www.devze.com 2023-03-13 19:54 出处:网络
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\

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

精彩评论

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

关注公众号