2015-11-04 33 views
1

具體來說,我的意思是電池的健康狀況,充電水平,電壓。看起來似乎沒有一種簡單的方法可以做到這一點。有誰知道是否有簡單的方法,或者如果沒有,如何實現它?如何在Mac上獲取電池信息?

+1

有我的Swift版本[在這個答案](http://stackoverflow.com/questions/31633503/fetch-the-battery-status-of-my-macbook-with-swift/31659561#31659561),它可能幫你。只要忽略關於橋接頭的第一部分並像通常那樣導入即可。 – Moritz

+0

我想要更多的信息,如電池溫度,年齡,像System Profiler顯示的製造商。 jBot-42的答案是最好的,但我無法接受它9分鐘。 – ssccsscc

回答

1

我創建了一個開源且易於使用的框架,名爲SystemInfoKit以獲取所有系統信息,CPU,內存和網絡使用情況以及溫度。

這裏是所有需要得到所有的電池信息代碼:

// 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); 

更多信息是here

+0

也許你的圖書館很有幫助,但爲了提高答案的質量,最好包括一些關於如何獲得圖書館電池信息的代碼。 – JAL

+1

這太棒了。我不知道這可能是如此簡單。溫度的東西也很棒。 – ssccsscc

+0

@ssccsscc你有他的github頁面和SystemInfoKit的源代碼的文檔/教程嗎?該用戶已刪除 – SkrewEverything