Cocoa 中的 UpdateSystemActivity 等价物是什么?

发布于 2024-08-02 17:04:17 字数 1772 浏览 2 评论 0原文

我正在将 Carbon 应用程序转换为 Cocoa 应用程序,但找不到与 Cocoa 等效的应用程序:

UpdateSystemActivity(UsrActivity);

有 Mac 用户愿意为我指出正确的方向吗?谢谢。

更新:我正在构建 64 位。构建 32 位工作正常,但当我构建 64 位时,我收到 UpdateSystemActivity(和其他)的符号未在此范围内声明的错误。

更新2:我正在导入以下内容:

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

构建 64 位时还需要导入其他内容吗?

UPDATE3:添加#import 没有帮助。我仍然收到编译器错误,告诉我 UpdateSystemActivity 和 UsrActivity 未在此范围内声明。

更新4:好的,在 OSServices/Power.h 上找不到文件。我正在针对 10.5 SDK 进行构建,快速搜索显示:

$ 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

但我得到:

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

I'm converting a Carbon app to a Cocoa app and I can't find the Cocoa equivalent for:

UpdateSystemActivity(UsrActivity);

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

UPDATE: I'm building 64bit. Building 32bit works fine, but I get symbol not declared in this scope errors for UpdateSystemActivity (and others) when I build for 64bit.

UPDATE2: I'm importing the following:

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

Is there some other thing I need to import when building 64bit?

UPDATE3: Adding #import <CoreServices/CoreServices.h> did not help. I still get compiler errors telling me UpdateSystemActivity and UsrActivity was not declared in this scope.

UPDATE4: Okay, file not found on OSServices/Power.h. I'm building against the 10.5 SDK and a quick search shows:

$ 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

Yet 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

行至春深 2024-08-09 17:04:17

在 OS X 10.6 及更高版本中,IOKit 可用于禁用睡眠。当您想要禁用睡眠时创建 IOPMAssertion 并在想要再次允许睡眠时销毁它。

#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.
}

更多信息:https://developer.apple.com/library/mac/ qa/qa1340/_index.html

In OS X 10.6 and later IOKit can be used to disable sleep. Create an IOPMAssertion when you want to disable sleep and destroy it when you want to allow sleep 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.
}

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

唠甜嗑 2024-08-09 17:04:17

这里的问题似乎是 OSServices.h 中的行,如果定义了 __LP64__ ,则排除 Power.h。在 10.5 上构建 64 位时,UpdateSystemActivity 确实是未定义的。

好消息是该符号确实存在于 CoreServices.framework 中。有两种方法可以访问它。

  1. 向前声明: extern "C" OSErr UpdateSystemActivity(UInt8);
  2. 显式包含您尝试过的 Power.h。您尝试的问题是 OSServices/ 找不到进入搜索路径的方式。您可以像这样包含它: #import

我手头没有 SnowLeopard 的副本,但接下来要做的就是检查它是否已修复。如果不是,请提交 RADAR,因为这显然是 SDK 错误。

The issue here appears to be the line in OSServices.h that excludes Power.h if __LP64__ is defined. When building 64 bit on 10.5 UpdateSystemActivity is indeed undefined.

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

  1. Forward declare it: extern "C" OSErr UpdateSystemActivity(UInt8);
  2. Explicitly include Power.h, which you tried. The issue with your attempt is that OSServices/ doesn't find it's way into the search path. You can include it like so: #import </Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/Power.h>

I don't have a copy of SnowLeopard handy, but the next thing to do would be to check if it's fixed there. If it isn't, file a RADAR as this is clearly an SDK bug.

北凤男飞 2024-08-09 17:04:17

您应该仍然能够从 Cocoa 应用程序中调用 UpdateSystemActivity ——它尚未被标记为已弃用。

API 的文档指定导入 CoreServices/CoreServices.h 来获取 API,但是通过标头(特别是在 OSServices/OSServices.h 中)搜索显示该文件在 64 位环境中被省略。尽管如此,Power.h 的某些部分(其中定义了 UpdateSystemActivity)对于 64 位是关闭的,而 UpdateSystemActivity 不是其中之一。

鉴于此,请尝试直接#import 并查看是否有效。 (您必须在项目中包含 CoreServices 框架才能找到标头。)

You should still be able to call UpdateSystemActivity from within your Cocoa app -- it has not been marked deprecated.

The documentation for the API specifies importing CoreServices/CoreServices.h to get the API -- however hunting through the headers (notably in OSServices/OSServices.h) shows that the file is omitted in a 64bit environment. Nevertheless, there are sections of Power.h (where UpdateSystemActivity is defined) that are turned off for 64bits, and UpdateSystemActivity is not one of them.

In light of that, try to #import <OSServices/Power.h> directly and see if that works. (You'll have to include the CoreServices framework in your project for the header to be found as well.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文