本文介绍了 - [NSRunningApplication activateWithOptions:]不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个程序,将某个应用程序(如果它启动)。这是我的代码:
I'm trying to create a program that will focus a certain application (if it is launched). Here is my code:
#import <Cocoa/Cocoa.h>
#import <stdio.h>
int main() {
// activate Firefox
NSArray *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier: @"org.mozilla.firefox"];
if ([apps count] == 0) {
printf("no matching app\n");
return 1;
}
if (![apps[0] activateWithOptions: NSApplicationActivateAllWindows]) {
printf("failed to activate\n");
return 1;
}
return 0;
}
当我运行这个,它打印无法激活,没有引起注意。
When I run this, it prints "failed to activate," and Firefox is not brought into focus. What am I doing wrong?
推荐答案
只需使用NSApplicationActivateIgnoringOtherApps修改器来激活。
Just use NSApplicationActivateIgnoringOtherApps modifier to activate. It's work ok.
另外,activateWithOptions:方法具有以下注释:
Additionally activateWithOptions: method has the following note:
这篇关于 - [NSRunningApplication activateWithOptions:]不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!