[英]Application not preventing shutdown on Mac
I am trying to get a Mac OS X application to prevent shutdown/sleep/restart. 我正在尝试获取Mac OS X应用程序以防止关机/睡眠/重新启动。 Here is my main.m from the Xcode project:
这是Xcode项目中的main.m:
//
// 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.
我从“防止关机”等部分的http://developer.apple.com/library/mac/#technotes/tn2002/tn2062.html获得了代码段。 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.
因此,当它退出时,将删除所有系统挂钩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.