user2877212
user2877212

Reputation:

Get Battery Charge Information Programmatically

(Xcode 6, OSX 10.10.3) How do I get the battery charge information of a Mac (Charge Status, Battery level, Cycle count, Maximum charge in mAH) programmatically?

Upvotes: 0

Views: 3205

Answers (2)

cyw
cyw

Reputation: 540

Use PFSystemKit. It is a framework that gives you about anything (besides sensors/smc info), including battery life, cycle, temperature and other stuff, just import the framework. Then add #import <PFSystemKit/PFSystemKit.h>. Then just add this code for battery info, make sure to change "cycleCount" to something else in a different case

 PFSystemKit *systemKit = [PFSystemKit investigate];
 NSString *batteryCycle = [systemKit.batteryReport cycleCount];
 [label setStringValue:batteryCycle];

https://github.com/perfaram/PFSystemKit

PS, sorry for a late response :P, and just a heads up I have a macmini so my output is NULL!

Upvotes: 0

Mumthezir VP
Mumthezir VP

Reputation: 6541

Hope this'll help you:

  1. It uses non-approved calls, so don’t post your application with this code or you may be rejected!

    http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/

  2. From Apple; so don't worry about this code: https://developer.apple.com/library/ios/samplecode/BatteryStatus/Introduction/Intro.html (With complete sample code)

Upvotes: 3

Related Questions