나는 official documentation에있는 어떤 방법도 발견하지 못했고, 클래스 덤프 된 private header은 클래스는 아니었다.
그래서 우리는 뭔가 들고 오지해야합니다. 순간 최고 "용액"I 생각하고있는 다운로드 시간을 추정 할 때 촬영 방식과 비슷하다/다운로드의 평균 속도를 계산하고 청구하고 그 속도가 (데이터 또는 전하의) 잔류량 분할 :
[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
}
충전은 선형이라고 가정합니다. 그렇지 않습니다. 배터리가 완전히 충전되면 충전 속도가 크게 느려집니다. – duskwuff
@duskwuff 예, 운영 체제에서보고 한 배터리 수준조차도 정확하지 않을 수 있습니다. 내가 왜 "평균"이라는 용어 **를 사용했다고 생각합니까? 젠장 –
감사 H2CO3 ... 일이, 내가 batterCharge의 method.any 제안 – iscavengers