所以我有这样的代码:
- (void)sendAnswerXlite:(NSDictionary*)softPhone
{
__block NSString * identifier = [softPhone objectForKey:kSoftPhoneAppIdentifier];
NSAssert(identifier != nil, @"Nil identifier argument in answer input");
dispatch_async(dispatch_get_menu_hotkey_queue(), ^{
// check if app is running
NSArray * apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:identifier];
if (apps != nil && [apps count] > 0)
{
NSRunningApplication * frontmostApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
NSRunningApplication * runningApp = [apps objectAtIndex:0];
if ( !([runningApp isEqualTo:frontmostApp]) )
{
[runningApp activateWithOptions:NSApplicationActivateAllWindows];
//[runningApp activateIgnoringOtherApps:YES];
[NSThread sleepForTimeInterval:1];
}
}
}
但即使我使用activateWithOptions或activateIgnoringOtherApps,它也只会将焦点设置到外部应用程序,但如果应用程序已经被最小化,那么它将不会显示窗口X-Lite,但菜单栏将显示(在这种情况下)X -lite。标识符只是应用程序的包标识符。