获取ios系统的电池电量比例,是否充电中,是否充满
2015-08-20 14:43
477 查看
</pre><pre name="code" class="objc"> // Find the battery level @try { // Get the device UIDevice *Device = [UIDevice currentDevice]; // Set battery monitoring on Device.batteryMonitoringEnabled = YES; // Set up the battery level float float BatteryLevel = 0.0; // Get the battery level float BatteryCharge = [Device batteryLevel]; // Check to make sure the battery level is more than zero if (BatteryCharge > 0.0f) { // Make the battery level float equal to the charge * 100 BatteryLevel = BatteryCharge * 100; } else { // Unable to find the battery level return -1; } // Output the battery level return BatteryLevel; } @catch (NSException *exception) { // Error out return -1; } // is charging @try { // Get the device UIDevice *Device = [UIDevice currentDevice]; // Set battery monitoring on Device.batteryMonitoringEnabled = YES; // Check the battery state if ([Device batteryState] == UIDeviceBatteryStateCharging || [Device batteryState] == UIDeviceBatteryStateFull) { // Device is charging return true; } else { // Device is not charging return false; } } @catch (NSException *exception) { // Error out return false; }
相关文章推荐
- iOS 通知中心
- 获取ios系统的deviceModel, deviceName, systemName, systemVersion
- 如何获得ios系统持续运行时间
- ios客户端websocket的helloworld
- Quartz2d从易到难全解析---绘制圆弧、圆、图片和文字
- self和下划线的用法区别
- iOS页面跳转及数据传递
- IOS 用keychain(钥匙串)保存用户名和密码
- IOS屏幕旋转
- ios应用数据存储方式
- iOS学习笔记12-m3u8文件信息总结
- #import <frameFile/classFile.h> not found file 解决办法
- iOS 动画效果
- iOS申请真机调试证书-图文详解
- [ios]ScrollView小结
- 研究IOS毛玻璃的效果
- ios,android使用HTML5开发问题汇总
- ios storyboadr(sizeClass)开发常用技巧及错误
- 根据滑动显隐状态栏的iOS实现
- iOS导航栏-关闭半透明