gpt4 book ai didi

macos - 调用 TransformProcessType() 时,应用程序菜单不显示

转载 作者:行者123 更新时间:2023-12-03 16:10:22 25 4
gpt4 key购买 nike

如果您像这样调用 TransformProcessType() :

ProcessSerialNumber psn = { 0, kCurrentProcess }; 
(void) TransformProcessType(&psn, kProcessTransformToForegroundApplication);

然后,除非您在应用程序中足够早地调用它(例如,在 applicationWillFinishLaunching 中),否则 cocoa 应用程序菜单不会显示。

最佳答案

我向 Apple 寻求帮助,他们为我提供了很好的帮助。引用:

The reason why the menu bar isn't show when you call TransformProcessType is that your app is already the active app (that is, [[NSRunningApplication currentApplication] isActive] returns YES) and the menu bar for an app is shown when the app is activated

这是他们的解决方法:

- (void)transformStep1 {
for (NSRunningApplication * app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.finder"]) {
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
break;
}
[self performSelector:@selector(transformStep2) withObject:nil afterDelay:0.1];
}

- (void)transformStep2
{
ProcessSerialNumber psn = { 0, kCurrentProcess };
(void) TransformProcessType(&psn, kProcessTransformToForegroundApplication);

[self performSelector:@selector(transformStep3) withObject:nil afterDelay:0.1];
}

- (void)transformStep3
{
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
}

关于macos - 调用 TransformProcessType() 时,应用程序菜单不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7596643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com