• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Displaying dialog at shutdown
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Displaying dialog at shutdown


  • Subject: Displaying dialog at shutdown
  • From: email@hidden
  • Date: Wed, 02 Jun 2010 16:13:46 +0000

I have a very simple application that runs as an LSUIElement/BackgroundOnly. Its only purpose is to display a message and play a short sound (3 seconds) to the user whenever it quits, which, since its a background only app, is only at shutdown/restart. I can use an AppleScript to force the app to quit and when doing that, I see the dialog every time, but if I actually restart the computer, I only see the dialog, maybe 1 out of 5 times. I use a timer to dismiss the dialog after 5 seconds and it seems that it is more likely to appear if the timer has a longer duration, say 15 seconds. My code is below. The window is an NSWindow instance that's been wired in IB.

//
// TurnOffMouseAppDelegate.m
// TurnOffMouse
//

#import "TurnOffMouseAppDelegate.h"

@implementation TurnOffMouseAppDelegate

@synthesize window;
@synthesize windowController;
@synthesize timer;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application

self.windowController = [[NSWindowController alloc] initWithWindow:self.window];
}



- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender{


[self playShutdownMessage:nil];

[self.windowController showWindow:nil];

self.timer = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(closeWindow:) userInfo:nil
repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];


return NSTerminateLater;
}

-(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finishedPlaying{

NSLog(@"Sound finished");
}

-(void)closeWindow:(id)sender{

[self.windowController close];
[NSApp replyToApplicationShouldTerminate:YES];
}

-(IBAction)playShutdownMessage:(id)sender{

BOOL playing;

NSLog(@"Playing sound");

NSSound * shutdown = [NSSound soundNamed:@"Shutdown Voice"];
[shutdown setDelegate:self];

if(![shutdown isPlaying])
playing = [shutdown play];
}
@end
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Displaying dialog at shutdown
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: The Unadopted Protocol
  • Next by Date: Re: [iPhone] more UIScrollView
  • Previous by thread: Re: The Unadopted Protocol
  • Next by thread: Re: Displaying dialog at shutdown
  • Index(es):
    • Date
    • Thread