views:

162

answers:

1

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];

+2  A: 

If you send activateIgnoringOtherApps then you're basically dismissing your own notification.

Azeem.Butt
OK. So it's choice between bringing your app to the front and bouncing the dock icon. I can't have both. Is that right?
John Gallagher
Bringing the app to front should involve first responder. I'm learning iPhone but i think that is similar.
JoePasq