Forum Navigation
You need to log in to create posts and topics.

Notification Manager ( old ) replacement

Posted by: fbcocoa.bw <fbcocoa.bw@...>

Brian wrote:

> Even though the old Notification Manager calls still work ( and there is no need to use pascal strings because they accept a pointer ), I’m hoping to find a modern replacement ( could be ’NS’ of ‘CF’ ). Searches of Xcode docs and the Carbon dev list did not find such support( looks like Eric Schlegel wrote a note about not having time to write a replacement ). I can find CFUserNotification ( bw wrote some nice examples in FB examples ) but a) I’m not sure if those work when the app is in the background and b) they don’t bounce the doc icon of the app. The NSNotification stuff doesn’t appear to cover this area on first reading but I could be wrong since it was only a cursory pass. Any thoughts?

I wonder if this will do it?

'---------------
/*
RequestUserAttention

Bernie Wylde 20100630

Notes:
- 'Compile as Objective-C'
- Run then click on another app

Request types:
- _kRUACritical bounces the dock icon until the app becomes active
- _kRUAInformational bounces the dock icon for one second
- Because this example puts up a modal dialog, the dock icon continues to bounce when _kRUAInformational
is used (see requestUserAttention: method discussion in NSApplication Class Reference)
*/

include "Tlbx Dialogs.incl"
include "Util_CE.incl"

BeginCFunction
long RequestUserAttention( UInt32 requestType )
{
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
NSInteger requestIdentifier = [[NSApplication sharedApplication] requestUserAttention:requestType];
[localPool release];
return (long)requestIdentifier;
}

void CancelUserAttentionRequest( long requestIdentifier )
{
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
[[NSApplication sharedApplication] cancelUserAttentionRequest:(NSInteger)requestIdentifier];
[localPool release];
}
EndC
toolbox fn RequestUserAttention( UInt32 requestType ) = long
toolbox CancelUserAttentionRequest( long requestIdentifier )

// request types
_kRUACritical = 0
_kRUAInformational = 10

local fn MyAppDeactivatedHandler( nextHandler as EventHandlerCallRef, theEvent as EventRef, userData as ptr ) as OSStatus
'~'1
dim as DialogRef dialogRef

fn RequestUserAttention( _kRUACritical )
fn CreateStandardAlert( _kAlertNoteAlert, @"kEventAppDeactivated.", 0, #0, @dialogRef )
fn RunStandardAlert( dialogRef, #0, #0 )
end fn = _noErr

fn CEAddEvent( _kEventClassApplication, _kEventAppDeactivated )
fn CEInstallApplicationEventHandler( @fn MyAppDeactivatedHandler, 0, 0 )

RunApplicationEventLoop()
'---------------

Bernie