What is the Cocoa equivalent of UpdateSystemActivity?

I am converting a Carbon application to a Cocoa application and I cannot find the Cocoa equivalent for:

UpdateSystemActivity(UsrActivity); 

Any Mac people who care there point me in the right direction? Thanks.

UPDATE . I am building 64 bit. The 32bit build works fine, but I get a character that is not declared in this error area for UpdateSystemActivity (and others) when I build for the 64-bit version.

UPDATE2 : I import the following:

 #import <Cocoa/Cocoa.h> #import <Carbon/Carbon.h> #import <OpenGL/CGLMacro.h> 

Is there anything else I need to import when creating 64-bit?

UPDATE3 : adding #import <CoreServices/CoreServices.h> did not help. I am still getting compiler errors reporting that UpdateSystemActivity and UsrActivity have not been declared in this area.

UPDATE4 . Well, the file was not found in OSServices / Power.h. I build against a 10.5 SDK and a quick search reveals:

 $ pwd /Developer/SDKs $ find . -name Power.h ./MacOSX10.3.9.sdk/Developer/Headers/CFMCarbon/OSServices/Power.h ./MacOSX10.3.9.sdk/Developer/Headers/CFMCarbon/Power.h ./MacOSX10.3.9.sdk/Developer/Headers/FlatCarbon/Power.h ./MacOSX10.3.9.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/Headers/Power.h ./MacOSX10.4u.sdk/Developer/Headers/CFMCarbon/OSServices/Power.h ./MacOSX10.4u.sdk/Developer/Headers/CFMCarbon/Power.h ./MacOSX10.4u.sdk/Developer/Headers/FlatCarbon/Power.h ./MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/Headers/Power.h ./MacOSX10.5.sdk/Developer/Headers/FlatCarbon/Power.h ./MacOSX10.5.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/Headers/Power.h 

But I get:

 Mac.mm:6:29: error: OSServices/Power.h: No such file or directory Mac.mm:6:29: error: OSServices/Power.h: No such file or directory 
+4
source share
3 answers

You can still call UpdateSystemActivity from your Cocoa application - it has not been deprecated.

The documentation for the API points to importing CoreServices/CoreServices.h to get the API - however, a search through the headers (especially in OSServices/OSServices.h ) indicates that the file is omitted in a 64-bit environment. However, there are Power.h sections (where UpdateSystemActivity ) that are disabled for 64 bits, and UpdateSystemActivity not one of them.

In light of this, try #import <OSServices/Power.h> directly and see if this works. (You must include a CoreServices environment in your project for the title to be found.)

+1
source

In OS X 10.6 and later, IOKit can be used to turn off sleep. Create an IOPMAssertion if you want to disable sleep and destroy it if you want to resolve spam again.

 #import <IOKit/pwr_mgt/IOPMLib.h> // kIOPMAssertionTypeNoDisplaySleep prevents display sleep, // kIOPMAssertionTypeNoIdleSleep prevents idle sleep // reasonForActivity is a descriptive string why sleep is disabled CFStringRef* reasonForActivity= CFSTR("Describe Activity Type"); IOPMAssertionID assertionID; IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &assertionID); if (success == kIOReturnSuccess) { //Add the work you need to do without the system sleeping here. success = IOPMAssertionRelease(assertionID); //The system will be able to sleep again. } 

Additional information: https://developer.apple.com/library/mac/qa/qa1340/_index.html

+4
source

The problem here is the line in OSServices.h that excludes Power.h if __LP64__ is defined. When building 64 bits on 10.5, UpdateSystemActivity is really undefined.

The good news is that the character does exist in CoreServices.framework. There are two ways to access it.

  • Forward declare: extern "C" OSErr UpdateSystemActivity (UInt8);
  • Explicitly turn on the Power.h that you tried. The problem with your attempt is that OSServices / cannot find the path to the search path. You can enable it like this: #import </Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/Power.h>

I do not have a copy of SnowLeopard, but the next task would be to check if this is fixed there. If this is not the case, write RADAR, as this is clearly an SDK error.

+2
source

All Articles