Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle iPhone 'Low Battery' pop up during a game

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.

like image 910
AbhinavVinay Avatar asked Jun 27 '12 21:06

AbhinavVinay


1 Answers

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.

like image 149
Almo Avatar answered Oct 05 '22 23:10

Almo