6

I was wondering how low battery alerts can be handled during a game. I used Cocos2D to make my game. I have the game pause when an interrupt such as a text or a call come in. But what about low battery alerts? Are they the same as other interrupts? It does not seem to be.

Is there any way I can detect when it comes up so that I can pause the game?

Thanks for your replies.

AbhinavVinay
  • 303
  • 6
  • 18
  • 3
    Are you saying that low battery alerts do not call applicationWillResignActive? They should be just the same as the other events – mackworth Jun 27 '12 at 21:48
  • mackworth's got a good point here. I don't recall having this problem with my iPhone app, and I never did the battery monitoring thing. – Almo Jun 27 '12 at 21:52
  • One of my testers said that when the low battery alert pops up the game does not pause. Now is there any way I can recreate or simulate that for testing without having to actually wait till my battery goes down to 20%? I want the event to happen with the phone connected to my gdb so I can check for myself if the applicationWillResignActive gets called or not. Thanks guys. – AbhinavVinay Jun 27 '12 at 22:05

2 Answers2

2

You can set up "battery monitoring" and get an event when this happens. Some links with info:

http://mobileorchard.com/new-in-iphone-30-tutorial-series-part-5-battery-monitoring

http://mobiledevelopertips.com/device/display-battery-state-and-level-of-charge.html

You know the event you're worried about is when it hits 20%, so I think you can just check for that amount and pause when it happens.

This is perhaps not a perfect solution, as Apple could decide it should happen at 25%, not 20%.

Also, Apple recommends turning this on only when you really need to know. So it should only be activated during gameplay, not on menus that aren't time sensitive.

Almo
  • 15,538
  • 13
  • 67
  • 95
0

Thanks guys. The problem however lied elsewhere. It happened to be a problem with one of the flags im checking upon resume. It should get reset when a user starts a new game, which I failed to do.

Lesson learnt: Be extra careful with global variables :) [I try to avoid them as much as possible]

I appreciate your replies and your answers. Thanks again.

AbhinavVinay
  • 303
  • 6
  • 18