I am working on a mobile game, which appearantly crashes when the Low Battery alert is displayed. It works fine on low memory, incoming calls and other messages.
Its a pain to test and debug this, since I can find no terminal or iPhone simulator way of simulating this situation, so I have to charge my phone up a little bit, launch the app, wait for it to drain its power, and start all over again.
Does anyone know of a way to produce this error in a realistic way? Hopefully something that isn't too stressful on my iPhone battery.
Unfortunately, there is no good way to simulate a low-battery environment. You actually will most likely need to physically charge your device's battery until it is just above the "low battery" state and then debug your application.
To address what others have said:
UILocalNotifications
. It isn't all that much different than just showing a UIAlertView in your app.Although it is a pain to have to wait for you device to actually hit the low-battery state, you could add some battery-draining code to your app to assist you. For example, using the GPS might drain the battery a bit quicker.
Good luck.
Assuming this is for testing purposes only, you could give the following private
UIDevice
methods a try:You'll have to experiment to see what parameters they expect, or whether they have an impact at all.
Did you try simulating the low battery notifications? There seems to be a project that does that: https://github.com/MegaEduX/LowBattery
In iOS there is way to simulate "Low Battery"
Battery monitoring is enabled by setting to YES a property of the UIDevice singleton:
iOS provides two type of battery monitoring events, one for when the state changes (e.g., charging, unplugged, full charged) and one that updates when the battery’s charge level changes. As was the case with proximity monitoring, you register callbacks to receive notifications: