如何向 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
指向一个指针或什么的?