Saturday, May 11, 2024
HomeiOS Developmentios - Test battery standing in when app is background

ios – Test battery standing in when app is background


Is it doable to test battery degree in swift whereas our software is in background?

Presently I’m engaged on one iOS (UIKit) software during which consumer can be alerted with system notification when charger is unplugged.

I attempted and this on a view controller However I need to run this code in background

UIDevice.present.isBatteryMonitoringEnabled = true
    let batteryState = UIDevice.present.batteryState
            change batteryState {
            case .charging:
                print("Charger plugged in.")
            case .full:
                print("Cost full")
            case .unplugged:
                print("Charger unplugged.")
            default:
                print("Battery state unknown.")
            }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular