I'm building a Mac OSX app that needs to poll a server every minute, or even less if the user wishes. Unfortunately the service doesn't support push...
Anyways, I would like to provide two options to the user:
Have a look at the IOPowerSources API.
IOPSCopyPowerSourcesList() to get a list of all available power sources.
IOPSGetPowerSourceDescription() will return a dictionary with information about a particular power source. According to the documentation, the key
kIOPSPowerSourceStateKey describes "the current source of power.
kIOPSBatteryPowerValue indicates power source is drawing internal power;
kIOPSACPowerValue indicates power source is connected to an external power source."
You can also set up a notification when the power sources change with
(NB: I haven't tested any of this, just looked at the documentation.)