获取当前手机的电池充电状态以及当前的电量
2015-08-11 15:59
363 查看
获取当前手机的电池充电状态以及当前的电量
- (void)viewDidLoad {
[super viewDidLoad];
//打开电池的监听
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
//获取电池的状态
UIDeviceBatteryState BatteryState = [UIDevice currentDevice].batteryState;
//获取剩余电量
范围在0.000000 至 1.000000之间
CGFloat batterylevel = [UIDevice currentDevice].batteryLevel;
//battery的状态
[UIDevice currentDevice].batteryState分为:
UIDeviceBatteryStateUnknown, 未知
UIDeviceBatteryStateUnplugged, // 未充电
UIDeviceBatteryStateCharging, //
正在充电
UIDeviceBatteryStateFull, //
满电
if (BatteryState == UIDeviceBatteryStateUnknown) {
NSLog(@"unknow");
}else{
NSLog(@"know");
//将剩余的电量用label显示。
self.current.text = [NSString stringWithFormat:@"%f",batterylevel];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//打开电池的监听
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
//获取电池的状态
UIDeviceBatteryState BatteryState = [UIDevice currentDevice].batteryState;
//获取剩余电量
范围在0.000000 至 1.000000之间
CGFloat batterylevel = [UIDevice currentDevice].batteryLevel;
//battery的状态
[UIDevice currentDevice].batteryState分为:
UIDeviceBatteryStateUnknown, 未知
UIDeviceBatteryStateUnplugged, // 未充电
UIDeviceBatteryStateCharging, //
正在充电
UIDeviceBatteryStateFull, //
满电
if (BatteryState == UIDeviceBatteryStateUnknown) {
NSLog(@"unknow");
}else{
NSLog(@"know");
//将剩余的电量用label显示。
self.current.text = [NSString stringWithFormat:@"%f",batterylevel];
}
}
相关文章推荐
- 解决/libc.so.6: version `GLIBC_2.17' not found问题
- 观察者模式
- foursquare url 令牌
- PostgreSQL一主两从实现及主从切换
- 智能指针的使用
- HDU 3572 Task Schedule(最大流-Dinic)
- listview滑动数据错乱
- Android项目中如何用好构建神器Gradle?
- 一个帖子学会Android开发四大组件
- gcc/g++使用简介
- C++ Primer 学习笔记_38_STL实践与分析(12)--集成的应用程序容器:文本查询程序
- 写给新手程序员的一封信
- Umbraco文档类型定义多个template
- Android项目中如何用好构建神器Gradle?
- Android项目中如何用好构建神器Gradle?
- 【机房收费系统】选择性查询数据库 及 限制特殊字符的输入
- msyql查看版本
- JMS 简单实例
- Android 自定义ImageView实现圆角/圆形 附加OnTouchListener详细注释以及Button圆角
- VMware linux 上网配置 虚拟机centos不能上网解决方案