0

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 methods of NSRunningApplication doesn't affect UIAgent processes.

Thanks in advance

markratledge
  • 17,322
  • 12
  • 60
  • 106
Nava Carmon
  • 4,523
  • 3
  • 40
  • 74

1 Answers1

1

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.

Nava Carmon
  • 4,523
  • 3
  • 40
  • 74