无法让 NSAlert 持续弹起停靠栏图标
我似乎遇到了与这个关于停止码头反弹的问题完全相反的问题。
我可以无法让我的应用程序不断弹起停靠栏图标!
我也讨厌不断弹跳的停靠图标,但在这种情况下,如果用户没有意识到我的应用程序无法启动,他们可能会损失数小时的跟踪数据时间。
这是我放入应用程序委托 applicationWillFinishLaunching: 方法中的代码。
if (!AXAPIEnabled()) { // I'm checking that Accessibility is turned on
NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert setMessageText:@"Lapsus cannot run."];
[alert addButtonWithTitle:@"Open Accessibility Prefs..."];
[alert addButtonWithTitle:@"Quit"];
[alert setInformativeText:@"Lapsus needs \"Enable access for assistive devices\" in the Accessibility pane of System Preferences to be turned on."];
[NSApp activateIgnoringOtherApps:YES];
int attentionrequest = [NSApp requestUserAttention:NSCriticalRequest];
NSInteger returnValue = [alert runModal];
....
[NSApp cancelUserAttentionRequest:attentionrequest];
}
我尝试删除 requestUserAttention 行。
我尝试将 requestUserAttention 行放在很多不同的地方:直接在 runModal 调用之前、第一件事等。
我尝试删除 activateIgnoringOtherApps 行。
无论我做什么,停靠栏图标都会弹起一次然后停止。
用户可能会看到我的应用程序,因为我将其带到前面,但如果他们在正确的时间单击,他们的活动应用程序可能会隐藏关键错误消息。
所以我想要一些东西,这样即使他们的码头被隐藏,他们也知道有些事情不对劲。
我正在 Mac OS X 10.5 Leopard 上构建它。关于我做错了什么有什么想法吗?或者 Leopard 不再支持连续弹跳的停靠图标?
更新:
我将方法调用放在 applicationWillFinishLaunching: 中,
一旦将其放入 applicationDidFinishLaunching: 中,并删除 activateIgnoringOtherApps: 调用,它就会按要求工作。
但是,我的问题仍然是“我可以将我的应用程序放在前面并弹起停靠栏图标吗?从第一个答案来看,似乎不能,尽管我不确定我明白为什么。
更新:
我不明白为什么,因为我没有仔细考虑。既然有人向我指出,窃取焦点意味着码头得到了它想要的东西,那么结论就很有意义
。
了 如果您希望用户注意,请不要使用 [NSApp activateIgnoringOtherApps:YES];
I seem to have the exact opposite problem than this question on stopping dock bounce.
I can't get my app to continually bounce the dock icon!
I too hate continually bouncing dock icons, but in this case if the user doesn't realise my app can't launch, they could potentially lose hours of time tracking data.
Here's my code that I've put in the app delegates applicationWillFinishLaunching: method.
if (!AXAPIEnabled()) { // I'm checking that Accessibility is turned on
NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert setMessageText:@"Lapsus cannot run."];
[alert addButtonWithTitle:@"Open Accessibility Prefs..."];
[alert addButtonWithTitle:@"Quit"];
[alert setInformativeText:@"Lapsus needs \"Enable access for assistive devices\" in the Accessibility pane of System Preferences to be turned on."];
[NSApp activateIgnoringOtherApps:YES];
int attentionrequest = [NSApp requestUserAttention:NSCriticalRequest];
NSInteger returnValue = [alert runModal];
....
[NSApp cancelUserAttentionRequest:attentionrequest];
}
I've tried removing the requestUserAttention line.
I've tried putting the requestUserAttention line in lots of different places: directly before the runModal call, first thing etc.
I've tried removing the activateIgnoringOtherApps line.
No matter what I do, the dock icon bounces once then stops.
The user will probably see that my app as I'm bringing it to the front, but there is a possibility that if they click at the right time, their active application will hide the critical error message.
So I want something so that even when their dock is hidden, they know something's not right.
I'm building this on Mac OS X 10.5 Leopard. Any ideas on what I'm doing wrong? Or does Leopard not support continually bouncing dock icons any more?
UPDATE:
I was putting the method call in applicationWillFinishLaunching:
As soon as I put it into applicationDidFinishLaunching:, and removed the activateIgnoringOtherApps: call, it worked as required.
However, my question still is "Can I bring my app to the front as well as bouncing the dock icon? From the first answer, it would seem not, although I'm not sure I understand why.
UPDATE:
I didn't understand why because I wasn't thinking it through. Now that it's been pointed out to me that stealing focus means the dock got what it wanted, it makes perfect sense.
Conclusion
If you want the users attention, don't use [NSApp activateIgnoringOtherApps:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发送 activateIgnoringOtherApps ,那么您基本上就是在忽略自己的通知。
If you send activateIgnoringOtherApps then you're basically dismissing your own notification.