1

Specifically I mean battery health, charge level, voltage. It does not look like there is an easy way to do it that exists. Does anyone know if there is an easy way or if not, how to implement it?

jscs
  • 63,694
  • 13
  • 151
  • 195
ssccsscc
  • 23
  • 5
  • 1
    There's my Swift version [in this answer](http://stackoverflow.com/questions/31633503/fetch-the-battery-status-of-my-macbook-with-swift/31659561#31659561), it may help you. Just ignore the first part about the bridging header and import like you would usually do. – Eric Aya Nov 04 '15 at 18:29
  • I want more info like the battery temperature, the age, the manufacturer like System Profiler shows. jBot-42's answer is the best but I cant accept it for 9 minutes. – ssccsscc Nov 04 '15 at 18:33

1 Answers1

1

I created an open-source and easy to use framework called SystemInfoKit to get all system info, CPU, memory, and network usage, and temperatures.

Here is all the code that is needed to get all the battery info:

// At top of file
#import <SystemInfoKit/SystemInfoKit.h>

JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];

JSKMBatteryUsageInfo batteryUsageInfo = systemMonitor.batteryUsageInfo;

NSLog(@"Battery Installed: %hhd", batteryUsageInfo.present);
NSLog(@"Battery Fully Charged: %hhd", batteryUsageInfo.full);
NSLog(@"Battery Connected To Charger: %hhd", batteryUsageInfo.acConnected);
NSLog(@"Battery Charging: %hhd", batteryUsageInfo.charging);

NSLog(@"Battery Voltage: %f V", batteryUsageInfo.voltage);
NSLog(@"Battery Amperage: %f A", batteryUsageInfo.amperage);

NSLog(@"Battery Design Capacity: %f mAh", batteryUsageInfo.designCapacity);
NSLog(@"Battery Maximum Capacity: %f mAh", batteryUsageInfo.maximumCapacity);
NSLog(@"Battery Current Capacity: %f mAh", batteryUsageInfo.currentCapacity);

NSLog(@"Battery Design Cycle Count: %lu Cycles", batteryUsageInfo.designCycleCount);
NSLog(@"Battery Cycle Count: %lu Cycles", batteryUsageInfo.cycleCount);
NSLog(@"Battery Age: %lu Days", batteryUsageInfo.ageInDays);

More info is here.

  • 1
    Maybe your library is helpful, but to increase the quality of your answer it would be best to include some code on how to get the battery information with your library. – JAL Nov 04 '15 at 18:35
  • 1
    This is wonderful. I had no idea it could be this easy. The temperature stuff is awesome too. – ssccsscc Nov 04 '15 at 18:41
  • @ssccsscc Do you have documentation/tutorial there on his github page and source code of SystemInfoKit? The user has deleted everything – SkrewEverything Feb 09 '17 at 01:03
  • It appears to be licensed under GPL 2 and available at this other location: https://github.com/xythobuz/JSystemInfoKit It says it is based on this: https://github.com/FergusInLondon/SMCWrapper – minopret Feb 11 '18 at 16:16