I am trying to get a Mac OS X application to prevent shutdown/sleep/restart. Here is my main.m from the Xcode project:
//
// main.m
// CurrencyConverter
//
//
#import <Cocoa/Cocoa.h>
OSErr QuitAppleEventHandler( const AppleEvent *appleEvt,
AppleEvent* reply, UInt32 refcon )
{
//returning userCanceledErr to cancel logout
return userCanceledErr;
}
int main(int argc, char *argv[])
{
OSErr err;
//Installing quit event handler
err = AEInstallEventHandler( kCoreEventClass,
kAEQuitApplication, NewAEEventHandlerUPP(
(AEEventHandlerProcPtr)QuitAppleEventHandler),
0, false );
if (err != noErr)
ExitToShell();
return NSApplicationMain(argc, (const char **) argv);
}
Somehow when I build and run, I am unable to get the required outcome. It still sleeps, shuts down and etc. I just want to know what I did wrong. I got the code snippet from http://developer.apple.com/library/mac/#technotes/tn2002/tn2062.html under the prevent shutdown etc part. I understand I can use kiosks and all but I am not sure how I can integrate it into my application. Thank you.
Nope!!!
Works fine for me. I think your issue is that the program is not running continually. So when it exits, all system hooks are removed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.