iphone – 剩余时间,直到充电完成,iOS

iphone – 剩余时间,直到充电完成,iOS,第1张

概述我在用 : UIDevice *myDevice = [UIDevice currentDevice];[myDevice setBatteryMonitoringEnabled:YES];float batLeft = [myDevice batteryLevel];int i = [myDevice batteryState]; int batinfo = batLeft * 1 我在用 :

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

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

解决方法 我在 official documentation中没有找到任何方法,在UIDevice类的class-dumped, private header中。

所以我们必须想出一些事情。我现在想到的最好的“解决方案”与估计下载时间的方法类似:计算下载/收费的平均速度,并将余数(数据或收费)除以该速度:

[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}
总结

以上是内存溢出为你收集整理的iphone – 剩余时间,直到充电完成,iOS全部内容,希望文章能够帮你解决iphone – 剩余时间,直到充电完成,iOS所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1086576.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存