0

I'm making a game.

If phone's battery under 60%, the yield decrement is 60 - current battery%

So, My question is: Can I get an information about battery % in iOS?

Jano
  • 62,815
  • 21
  • 164
  • 192
CenoX
  • 306
  • 1
  • 2
  • 12

3 Answers3

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);
Jano
  • 62,815
  • 21
  • 164
  • 192
2

iOS Developer Library

UIDevice Class Reference

You can download sample from here.

2

If you wa t to get the Battery charge use this [UIDevice currentDevice].batteryLevel

It will return a float 0.0 - 1.0.

Arbitur
  • 38,684
  • 22
  • 91
  • 128