我在做游戏。
如果手机电池电量低于 60%,则产量递减量为 60 - current battery%
所以,我的问题是:我可以在 iOS 中获取有关电池百分比的信息吗?
如果您想获得电池充电,请使用此[UIDevice currentDevice].batteryLevel
它将返回一个浮点数 0.0 - 1.0。
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);