Re: Handling sleep and wake
Re: Handling sleep and wake
- Subject: Re: Handling sleep and wake
- From: Eric Peyton <email@hidden>
- Date: Fri, 5 Apr 2002 08:08:32 -0600
Fire.app handles sleep wake - check out the code, it's in its
MainController.m file ...
io_object_t powerConnection;
- (void)registerForSleepNotifications
{
CFRunLoopSourceRef rls;
IONotificationPortRef thePortRef;
io_object_t notifier;
powerConnection=IORegisterForSystemPower( NULL, &thePortRef,
sleepNotification,
¬ifier );
if(powerConnection==0)
NSLog(@"IORegisterForSystemPower failed.");
rls = IONotificationPortGetRunLoopSource(thePortRef);
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls,
kCFRunLoopDefaultMode);
CFRelease(rls);
return;
}
void sleepNotification(
void * refcon,
io_service_t service,
natural_t messageType,
void * messageArgument )
{
switch(messageType)
{
case kIOMessageSystemWillSleep:
// tell all the service controllers to disconnect due to
sleep
// go to sleep
IOAllowPowerChange(powerConnection, (long) messageArgument);
break;
case kIOMessageCanSystemSleep:
IOAllowPowerChange(powerConnection, (long) messageArgument);
break;
case kIOMessageSystemHasPoweredOn:
// awake
break;
}
}
Eric
On Friday, April 5, 2002, at 02:02 AM, Jamie Curmi wrote:
Hi All,
Is there any way to have a cocoa application respond to sleep and wake
events?
Basically I want my application to disconnect from a server on sleep,
and reconnect automatically on wake. I couldn't find any notification
methods that seem to handle this. Can it be done? Is there anywhere
with some sample code?
Hope you can help. Thanks.
Jamie
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.