-[NSRunningApplication activateWithOptions:] 不工作
-[NSRunningApplication activateWithOptions:] not working
我正在尝试创建一个将专注于特定应用程序(如果已启动)的程序。这是我的代码:
#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;
}
当我 运行 这样做时,它会打印 "failed to activate," 并且 Firefox 没有进入焦点。我做错了什么?
只需使用 NSApplicationActivateIgnoringOtherApps 修饰符激活即可。工作正常。
另外activateWithOptions:方法有以下注意事项:
This method will return NO if the application has quit, or is not a
type of application than can be activated.
我正在尝试创建一个将专注于特定应用程序(如果已启动)的程序。这是我的代码:
#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;
}
当我 运行 这样做时,它会打印 "failed to activate," 并且 Firefox 没有进入焦点。我做错了什么?
只需使用 NSApplicationActivateIgnoringOtherApps 修饰符激活即可。工作正常。
另外activateWithOptions:方法有以下注意事项:
This method will return NO if the application has quit, or is not a type of application than can be activated.