src/power/uikit/SDL_syspower.m
branchiOS-improvements
changeset 9506 18e3f94bd860
parent 8223 18ffe88a2148
child 9619 b94b6d0bff0f
     1.1 --- a/src/power/uikit/SDL_syspower.m	Tue Jul 29 00:05:48 2014 -0300
     1.2 +++ b/src/power/uikit/SDL_syspower.m	Tue Jul 29 00:36:12 2014 -0300
     1.3 @@ -50,24 +50,24 @@
     1.4  SDL_bool
     1.5  SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
     1.6  {
     1.7 -    UIDevice *uidev = [UIDevice currentDevice];
     1.8 +    @autoreleasepool {
     1.9 +        UIDevice *uidev = [UIDevice currentDevice];
    1.10  
    1.11 -    if (!SDL_UIKitLastPowerInfoQuery) {
    1.12 -        SDL_assert([uidev isBatteryMonitoringEnabled] == NO);
    1.13 -        [uidev setBatteryMonitoringEnabled:YES];
    1.14 -    }
    1.15 +        if (!SDL_UIKitLastPowerInfoQuery) {
    1.16 +            SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
    1.17 +            uidev.batteryMonitoringEnabled = YES;
    1.18 +        }
    1.19  
    1.20 -    /* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
    1.21 -     *  monitoring if the app hasn't queried it in the last X seconds.
    1.22 -     *  Apparently monitoring the battery burns battery life.  :)
    1.23 -     *  Apple's docs say not to monitor the battery unless you need it.
    1.24 -     */
    1.25 -    SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
    1.26 +        /* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
    1.27 +         *  monitoring if the app hasn't queried it in the last X seconds.
    1.28 +         *  Apparently monitoring the battery burns battery life.  :)
    1.29 +         *  Apple's docs say not to monitor the battery unless you need it.
    1.30 +         */
    1.31 +        SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
    1.32  
    1.33 -    *seconds = -1;   /* no API to estimate this in UIKit. */
    1.34 +        *seconds = -1;   /* no API to estimate this in UIKit. */
    1.35  
    1.36 -    switch ([uidev batteryState])
    1.37 -    {
    1.38 +        switch (uidev.batteryState) {
    1.39          case UIDeviceBatteryStateCharging:
    1.40              *state = SDL_POWERSTATE_CHARGING;
    1.41              break;
    1.42 @@ -84,11 +84,12 @@
    1.43          default:
    1.44              *state = SDL_POWERSTATE_UNKNOWN;
    1.45              break;
    1.46 +        }
    1.47 +
    1.48 +        const float level = uidev.batteryLevel;
    1.49 +        *percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
    1.50 +        return SDL_TRUE; /* always the definitive answer on iOS. */
    1.51      }
    1.52 -
    1.53 -    const float level = [uidev batteryLevel];
    1.54 -    *percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
    1.55 -    return SDL_TRUE;            /* always the definitive answer on iOS. */
    1.56  }
    1.57  
    1.58  #endif /* SDL_POWER_UIKIT */