ios - 获取电池状态

标签 ios

我正在制作游戏。

如果手机的电池电量低于 60%,则产量递减为 60 - 当前电池电量%

所以,我的问题是: 我可以在 iOS 中获取有关电池百分比的信息吗?

最佳答案

NSArray *stateArray = @[@"Battery state is unknown", 
                        @"Battery is not plugged into a charging source", 
                        @"Battery is charging", 
                        @"Battery state is full"];

NSString *status = [NSString stringWithFormat:@"Battery state: %@, Battery level: %0.2f%%",
                    stateArray[[UIDevice currentDevice].batteryState],
                    [UIDevice currentDevice].batteryLevel * 100];

NSLog(@"%@", status);

关于ios - 获取电池状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19197656/

相关文章:

iphone - AlertView 的 init 方法中的参数

ios - 使用 NMSSH 库为 "sudo"命令提供密码

ios - Facebook SDK 使用 Swift 3 iOS 10 登录

ios - 在选定的时间范围内修剪视频

ios - 将所有 DNS 请求重定向到 iOS 应用程序中的自定义解析器

ios - iOS 应用程序的 iPhone 语音识别?

iphone - 多次更自然地为点设置动画

ios - 在 Swift 中为选定的 UIPickerView 行设置动画背景颜色

iOS。使用 USB 麦克风以 96kHz 录制

ios - 如何在 Swift 中使用 URLSession 添加 UIActivityIndi​​catorView?