Search code examples
iosbattery

iOS: is it possible to programmatically read the phone battery percentage?


Is it possible to programmatically read the phone battery percentage from an iOS App?


Solution

  • You can use the below code.

    if (![[UIDevice currentDevice] isBatteryMonitoringEnabled])
     {
       [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
     }
     NSLog(@"battery : %f", [[UIDevice currentDevice] batteryLevel]);