1

The deprecated UpdateSystemActivity() works by "notifying the Power Manager that activity has taken place and the timers used to measure idle time should be updated to the time of this call."

The documentation recommends using IOPMAssertionCreateWithName(...) but this method doesn't reset the timer for the idle time; it prevents the machine from sleeping forever until IOPMAssertionRelease(...) is called. Using IOPMAssertionCreateWithName(...) is unsuitable for my current codebase.

Are there any non-deprecated methods that reset the timer for measuring idle time?

Thanks!

Lenny
  • 388
  • 3
  • 15
  • There are some "timeout" methods these days FWIW: IOPMAssertionCreateWithDescription how did you measure idle time before? – rogerdpack Dec 15 '17 at 21:12

3 Answers3

1

Here is the answer in Swift 3.x:

var assertionID : IOPMAssertionID = 0 _ = IOPMAssertionDeclareUserActivity("TeslaWatcher" as CFString, kIOPMUserActiveLocal, &assertionID)

Tornado
  • 115
  • 6
1

"it prevents the machine from sleeping forever until IOPMAssertionRelease(...) is called"

I don't observe this behavior with macOS 10.15, not for IOPMAssertionCreateWithName(...) . In contrast to documentation IOPMAssertionDeclareUserActivity(...) seems to behave like UpdateSystemActivity() and needs to be called periodically.

See snippet of Screen Saver timer event examples/common/ScreenSaver.cpp

Sam Ginrich
  • 661
  • 6
  • 7
0

I ran into this same problem and discovered this closely related question which points to the IOPMAssertionDeclareUserActivity function.

You can use this:

IOPMAssertionID assertionID; 
IOPMAssertionDeclareUserActivity(CFSTR(""), kIOPMUserActiveLocal, &assertionID);
Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215