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