I'm trying to include a battery feature to my widget, but I can't seem to get the mobile's battery percentage...
I tried:
import UIKit
struct BatteryControl {
static func getBatteryPercent() -> Int {
UIDevice.current.isBatteryMonitoringEnabled = true
print("BATTERY : \(UIDevice.current.batteryLevel)")
return Int(UIDevice.current.batteryLevel * 100)
}
}
It just keeps showing that the battery is -1.0
EDIT SOLUTION: Simulator always showing the batter as -1.0, but whem testing it on a real deivce, it showed the correct value.