David Karlsson
David Karlsson

Reputation: 9696

Is there a way to detect if the charger is disconnected

Is there a way to detect if the charger is disconnected on a mac computer.

i.e. is it possible to make an app that listens for an "charger-connected"/"charger-disconnected" event?

Like For ios:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

if ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) {
    NSLog(@"Device is charging.");
}

But I would like an event-listener, for example: -(void) didDisconnectCharger:(id)sender.

Upvotes: 2

Views: 239

Answers (1)

Krumelur
Krumelur

Reputation: 32507

I think the function you are looking for is IOPSNotificationCreateRunLoopSource in IOKit.

Upvotes: 2

Related Questions