【发布时间】:2013-12-30 17:01:15
【问题描述】:
如何向 Apple 事件监听器添加回调方法,例如:
CFRunLoopSourceRef IOPSNotificationCreateRunLoopSource(IOPowerSourceCallbackType callback,
void *context);
如何将方法或块添加到以下方法,以便在电源更改时可以记录如下内容(我可以看到它是 C++,但 NSLog 在 Obj-C++ 中仍然有效)类似于:
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
CFRunLoopSourceRef IOPSNotificationCreateRunLoopSource(callbackMethod(),
void *context);
}
void callbackMethod(){
// NSLog("No power connected"); or NSLog("Power connected");
}
我想我需要改变:
IOPowerSourceCallbackType callback
指向指针或其他东西?
【问题讨论】:
标签: c++ objective-c macos cfrunloop