• 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
Re: Handling sleep and wake
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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,
&notifier );

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.

References: 
 >Handling sleep and wake (From: Jamie Curmi <email@hidden>)

  • Prev by Date: Help on startup volume name and NSEvent characters
  • Next by Date: Re: Color entire table view row
  • Previous by thread: Handling sleep and wake
  • Next by thread: NSComboBoxCell in a NSTableView
  • Index(es):
    • Date
    • Thread