-
-
Save RSBOMB/88e0c6214d20a9020298e3c4bbdc3c58 to your computer and use it in GitHub Desktop.
Script to get iOS device battery info from the BatteryCenter private framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
guard case let batteryCenterHandle = dlopen("/System/Library/PrivateFrameworks/BatteryCenter.framework/BatteryCenter", RTLD_LAZY) where batteryCenterHandle != nil else { | |
fatalError("BatteryCenter not found") | |
} | |
guard let c = NSClassFromString("BCBatteryDeviceController") as? NSObjectProtocol else { | |
fatalError("BCBatteryDeviceController not found") | |
} | |
let instance = c.performSelector("sharedInstance").takeUnretainedValue() | |
if let devices = instance.valueForKey("connectedDevices") as? [AnyObject] { | |
// You will have more than one battery in connectedDevices if your device is using a Smart Case | |
for battery in devices { | |
print(battery) | |
} | |
} | |
// Simulator | |
// <BCBatteryDevice: 0x7fc208d23930;**FAKE DEVICE** vendor = Apple; productIdentifier = 0; parts = (null); identifier = 1; matchIdentifier = (null); baseIdentifier = InternalBattery-0; name = iPad; groupName =InternalBattery-0; percentCharge = 100; lowBattery = NO; connected = YES; charging = NO; internal = YES; powerSource = YES; poweredSoureState = Unknown; transportType = 1 > | |
// iPhone 6 | |
// BCBatteryDevice: 0x15764a3d0; vendor = Apple; productIdentifier = 0; parts = (null); matchIdentifier = (null); baseIdentifier = InternalBattery-0; name = iPhone; percentCharge = 63; lowBattery = NO; connected = YES; charging = YES; internal = YES; powerSource = YES; poweredSoureState = AC Power; transportType = 1 > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment