0

How can I get battery cycles count and wear rate or at least max capacity, so that my app could be accepted?

astrolka
  • 133
  • 1
  • 11

2 Answers2

0

This is how you get battery level

[UIDevice currentDevice].batteryLevel

this is how you get battery state

UIDeviceBatteryState currentState = [UIDevice currentDevice].batteryState;

this is the enum of UIDeviceBatteryState

typedef NS_ENUM(NSInteger, UIDeviceBatteryState) {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,   // on battery, discharging
    UIDeviceBatteryStateCharging,    // plugged in, less than 100%
    UIDeviceBatteryStateFull,        // plugged in, at 100%
} __TVOS_PROHIBITED; 
Rajat
  • 10,977
  • 3
  • 38
  • 55
  • Unfortunately this is not what I'm looking for(( I'm interested whether there is a way to get maximal battery capacity – astrolka Nov 10 '16 at 12:51
0

Objective C:

  [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
    UIDevice *myDevice = [UIDevice currentDevice];

    [myDevice setBatteryMonitoringEnabled:YES];
    double batLeft = (float)[myDevice batteryLevel] * 100;
    NSLog(@"%.f",batLeft);


NSLog(@"%@",[NSString stringWithFormat:@"%.f%%", batLeft]);

Swift:

try
{
    UIDevice.CurrentDevice.BatteryMonitoringEnabled = true;
    _Battery.Level = (int)(UIDevice.CurrentDevice.BatteryLevel * IOSBatteryLevelScalingFactor);
    _Battery.State = UIDevice.CurrentDevice.BatteryState;
}
catch (Exception e)
{
    ExceptionHandler.HandleException(e, "BatteryState.Update");
    throw new BatteryUpdateException();
}
finally
{
    UIDevice.CurrentDevice.BatteryMonitoringEnabled = false;
}

Find reference from here

Community
  • 1
  • 1
Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65