Supressing NSAlertPanel with time litmit

  • I have created a NSGetCriticalAlertPanel  and run it by runModalForWindow:
    method of NSApp. I have one "OK" button in the alert. Now I want to close
    the alert panel after some delay (suppose 5 seconds) if  "OK" button is not
    clicked within that time period. As it is runModal I am not able to close
    the alert before "OK" button clicked.



    Is there any way to close the runModal  NSAlertPanel giving time constraint.



    Thanks
  • On 2007 Sep, 12, at 21:12, Jajati Sahu wrote:

    > I have created a NSGetCriticalAlertPanel  and run it by
    > runModalForWindow:
    > method of NSApp. I have one "OK" button in the alert. Now I want to
    > close
    > the alert panel after some delay (suppose 5 seconds) if  "OK"
    > button is not
    > clicked within that time period. As it is runModal I am not able to
    > close
    > the alert before "OK" button clicked.
    >
    >
    >
    > Is there any way to close the runModal  NSAlertPanel giving time
    > constraint.

    Those modal sessions can be tricky, and easily crashed.  I'm not sure
    if this will work, but try scheduling a 5-second NSTimer targetting
    the following method.  The symbol _modalSession is an instance
    variable, the NSModalSession that you got when you started the modal
    session.

    - (void)endModalSession {
        if (_modalSession) {
            int response = [NSApp runModalSession:_modalSession] ;
            BOOL done = (response != NSRunContinuesResponse) ;
            if (!done) {
                // if() since re-sending -stopModal might cause a crash
                [NSApp stopModal] ;
            }
            [NSApp endModalSession:_modalSession] ;

            _modalSession = 0 ;
        }
    }
  • On 13 sept. 07, at 6:12, Jajati Sahu wrote:

    > I have created a NSGetCriticalAlertPanel  and run it by
    > runModalForWindow:
    > method of NSApp. I have one "OK" button in the alert. Now I want to
    > close
    > the alert panel after some delay (suppose 5 seconds) if  "OK" button
    > is not
    > clicked within that time period. As it is runModal I am not able to
    > close
    > the alert before "OK" button clicked.
    >
    >
    >
    > Is there any way to close the runModal  NSAlertPanel giving time
    > constraint.

    I asked a similar question to the NSEvent oracle  at WWDC.

    You can probably add a NSTimer to the NSModalPanelRunLoopMode mode that
    will call:

    [NSApp abortModal];

    when the delay has expired. stopModal will not correctly work in this
    case.

    runModalForWindow: will then return NSRunAbortedResponse.
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today