剩余的时间直到收费完成,iOS

我在用 :

UIDevice *myDevice = [UIDevice currentDevice]; [myDevice setBatteryMonitoringEnabled:YES]; float batLeft = [myDevice batteryLevel]; int i = [myDevice batteryState]; int batinfo = batLeft * 100; 

find电池状态。 我正在寻找,如何find剩余的时间,直到收费完成。 例如:剩下1小时20分钟。 我怎样才能以编程方式find它?

在官方文档中 ,我还没有find任何方法,在UIDevice类的类转储的私有头 文件中也没有find。

所以我们必须拿出一些东西。 目前我所想到的最好的“解决scheme”与估算下载时间时采用的方法类似:计算下载/计费的平均速度,并将剩余数量(数据或费用)除以该速度:

 [UIDevice currentDevice].batteryMonitoringEnabled = YES; float prevBatteryLev = [UIDevice currentDevice].batteryLevel; NSDate *startDate = [NSDate date]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryCharged) name:UIDeviceBatteryLevelDidChangeNotification object:nil ]; - (void)batteryCharged { float currBatteryLev = [UIDevice currentDevice].batteryLevel; // calculate speed of chargement float avgChgSpeed = (prevBatteryLev - currBatteryLev) / [startDate timeIntervalSinceNow]; // get how much the battery needs to be charged yet float remBatteryLev = 1.0 - currBatteryLev; // divide the two to obtain the remaining charge time NSTimeInterval remSeconds = remBatteryLev / avgChgSpeed; // convert/format `remSeconds' as appropriate }