Nie znalazłem żadnej metody na to w official documentation, ani w klasie po cenach dumpingowych, private header z klasy .
Musimy więc wymyślić coś. Najlepsze "rozwiązanie", które mam na myśli, jest podobne do podejścia przyjętego przy szacowaniu czasu pobierania: obliczaniu średniej prędkości pobierania/ładowania i dzieleniu pozostałej kwoty (danych lub opłat) na tę prędkość:
[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
}
Zakładając, że ładowanie jest liniowe - nie jest. Ładowanie ładuje się dramatycznie, gdy bateria zbliża się do pełnej. – duskwuff
@duskwuff tak, a nawet poziom naładowania baterii zgłoszony przez system operacyjny może nie być dokładny itp. Dlaczego według Ciebie użyłem terminu ** "średnia" ** w całym tekście? Gówno się dzieje ... –
Dzięki H2CO3, nie jestem w stanie nazwać metody batterCharge.na sugestia – iscavengers