How to work with iPhone "Low Battery" appears during the game

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

Is there any way to detect when it appears so that I can pause the game?

Thank you for your responses.

+6
source share
2 answers

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

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 that the event you are worried about is when it reaches 20%, so I think you can just check this amount and pause when it happens.

This may not be the ideal solution, as Apple may decide that this should happen at 25%, not 20%.

In addition, Apple recommends enabling this only when you really need to know. Therefore, it should be activated only during the game, and not in the menu, which does not depend on time.

+2
source

Thanks guys. However, the problem was elsewhere. This was a problem with one of the flags that are checked during renewal. It should get reset when the user starts a new game, which I could not do.

Lesson learned: be careful with global variables :) [I try to avoid them as much as possible)

I appreciate your answers and your answers. Thanks again.

0
source

Source: https://habr.com/ru/post/919189/


All Articles