iOS , Android. , , .
, .
UIDevice.currentDevice().batteryMonitoringEnabled = true
if (UIDevice.currentDevice().batteryState != .Unplugged) {
print("Device is plugged in.")
}
, , . . , , App Store.
func applicationDidEnterBackground(application: UIApplication) {
UIDevice.currentDevice().batteryMonitoringEnabled = true
NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: #selector(batteryCheck), userInfo: nil, repeats: true)
}
func batteryCheck() {
if (UIDevice.currentDevice().batteryState != .Unplugged) {
print("Device is charging.")
} else {
print("Device is NOT charging.")
}
}