Battery Low Warning Handling / remain active with screen lock

Forgive me if this has been asked already – I can’t seem to figure out if it’s possible to handle the low battery warning in Corona. The current app I am working on utilizes a silent timer – you get an audio alert when the timer has completed. However, if the low battery warning pops-up, the app suspends, and the timer never completes. I know other iOS apps can handle the low battery warning, and not suspend in the background. Is it possible to force a corona app to remain active through this kind of warning?

Also, I would like to be able to keep my timer app active even if the user hits the screen lock button. Again, I know other iOS apps that behave this way. Is it possible to handle the screen lock event? [import]uid: 87249 topic_id: 36330 reply_id: 336330[/import]

As far as timers and lock screens, unless those are built by Apple or get special permission, the way they work is to detect that they have been suspended and save the time it was stopped. When they get a resume event, they start counting again adding the difference in time between the suspend and resume events.

Now the low battery warning I would think would suspend your app, but if it was running in the foreground, it should still be running in the foreground and you should get a regular suspend/resume set of events.

There are two parts to supporting this. First your app must not exit on suspend. This is a setting in build.settings. Next you have to setup a Runtime: listener for system events and have a function that responds to the suspend and resume events, stopping and restarting your timers accordingly.

[import]uid: 199310 topic_id: 36330 reply_id: 144350[/import]

I appreciate your response; however, I think you may have misunderstood. I do handle suspend/resume events without issue. The problem is, I don’t want the app to suspend at all when the battery warning appears (which it does), nor do I want it to suspend when the screen lock is activated. I don’t want the suspend event to fire. My app is designed to be ignored until an audio notification is triggered. If the app suspends, then the audio notification will not be triggered. I know this is possible natively with iOS code, but it seems impossible with Corona. [import]uid: 87249 topic_id: 36330 reply_id: 144367[/import]

It’s going to suspend when the device goes to sleep. Unless you are Apple and have access to backgrounding (using Objective C) that they don’t give to mortals, you’re not going to be able to stay live while the phone is locked/sleeping. There are a hand full of very specific things they let a sleeping app do which includes play music, check the GPS periodically, download newstand content, and a few others. See:

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

and click on the uiBackgroundModes link. If you’re not doing one of these, there is no running in the background or you’re Apple and can do what you want.

Apple is going to suspend your app on low battery warnings. There is nothing Corona Labs can do about this:

http://www.ios-developer.net/iphone-ipad-programmer/development/alert-view/system-alerts

Since you’re not Apple, the best thing you can do is to update your visual timer to account for the time the app was suspended.

You mentioned an audio alert… I don’t know if this is the same as playing music in the background or not. That is one of the things an app can continue to do, but I don’t know if that’s the case here.
[import]uid: 199310 topic_id: 36330 reply_id: 144369[/import]

Weird. Basically, my app displays a countdown timer, so there’s a timer running, and the display is updating, and when the countdown has completed, an audio file plays.

Here is an example of an iOS app that can do exactly that – Meditation Timer: https://itunes.apple.com/us/app/meditation-timer-free/id515571863?mt=8

It’s a free download – feel free to try it out. I’ve tested this particular app myself, and when the low battery alert happens, the alert still shows up on screen, but without vibration and you can still see the meditation timer counting down in the background. If you ignore the battery warning, the app still does its audio & vibration notifications. Also, this app will continue if the screen lock has been activated, and it will still provide its audio & vibration notifications. So it must be possible. This is exactly what I need my app to do.
[import]uid: 87249 topic_id: 36330 reply_id: 144376[/import]

I think they might be doing it with local notifications – that should take care of the screen lock issue. I wonder if it’ll work with the battery alert. I’ll give it a shot.

[import]uid: 87249 topic_id: 36330 reply_id: 144377[/import]

Using local notifications works well for when the screen is locked and the app is suspended. However, when the battery alert is displayed, the app is suspended; however, the notifications don’t seem to fire.

Actually, I’m having trouble getting the notifications to fire at all when the app is in the foreground – the notification listener fires, so I can handle that, but the notification alerts (audio, etc) don’t fire. Just using the local notifications sample code – am I missing something?

[import]uid: 87249 topic_id: 36330 reply_id: 144425[/import]

As far as timers and lock screens, unless those are built by Apple or get special permission, the way they work is to detect that they have been suspended and save the time it was stopped. When they get a resume event, they start counting again adding the difference in time between the suspend and resume events.

Now the low battery warning I would think would suspend your app, but if it was running in the foreground, it should still be running in the foreground and you should get a regular suspend/resume set of events.

There are two parts to supporting this. First your app must not exit on suspend. This is a setting in build.settings. Next you have to setup a Runtime: listener for system events and have a function that responds to the suspend and resume events, stopping and restarting your timers accordingly.

[import]uid: 199310 topic_id: 36330 reply_id: 144350[/import]

I appreciate your response; however, I think you may have misunderstood. I do handle suspend/resume events without issue. The problem is, I don’t want the app to suspend at all when the battery warning appears (which it does), nor do I want it to suspend when the screen lock is activated. I don’t want the suspend event to fire. My app is designed to be ignored until an audio notification is triggered. If the app suspends, then the audio notification will not be triggered. I know this is possible natively with iOS code, but it seems impossible with Corona. [import]uid: 87249 topic_id: 36330 reply_id: 144367[/import]

It’s going to suspend when the device goes to sleep. Unless you are Apple and have access to backgrounding (using Objective C) that they don’t give to mortals, you’re not going to be able to stay live while the phone is locked/sleeping. There are a hand full of very specific things they let a sleeping app do which includes play music, check the GPS periodically, download newstand content, and a few others. See:

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

and click on the uiBackgroundModes link. If you’re not doing one of these, there is no running in the background or you’re Apple and can do what you want.

Apple is going to suspend your app on low battery warnings. There is nothing Corona Labs can do about this:

http://www.ios-developer.net/iphone-ipad-programmer/development/alert-view/system-alerts

Since you’re not Apple, the best thing you can do is to update your visual timer to account for the time the app was suspended.

You mentioned an audio alert… I don’t know if this is the same as playing music in the background or not. That is one of the things an app can continue to do, but I don’t know if that’s the case here.
[import]uid: 199310 topic_id: 36330 reply_id: 144369[/import]

Weird. Basically, my app displays a countdown timer, so there’s a timer running, and the display is updating, and when the countdown has completed, an audio file plays.

Here is an example of an iOS app that can do exactly that – Meditation Timer: https://itunes.apple.com/us/app/meditation-timer-free/id515571863?mt=8

It’s a free download – feel free to try it out. I’ve tested this particular app myself, and when the low battery alert happens, the alert still shows up on screen, but without vibration and you can still see the meditation timer counting down in the background. If you ignore the battery warning, the app still does its audio & vibration notifications. Also, this app will continue if the screen lock has been activated, and it will still provide its audio & vibration notifications. So it must be possible. This is exactly what I need my app to do.
[import]uid: 87249 topic_id: 36330 reply_id: 144376[/import]

I think they might be doing it with local notifications – that should take care of the screen lock issue. I wonder if it’ll work with the battery alert. I’ll give it a shot.

[import]uid: 87249 topic_id: 36330 reply_id: 144377[/import]

Using local notifications works well for when the screen is locked and the app is suspended. However, when the battery alert is displayed, the app is suspended; however, the notifications don’t seem to fire.

Actually, I’m having trouble getting the notifications to fire at all when the app is in the foreground – the notification listener fires, so I can handle that, but the notification alerts (audio, etc) don’t fire. Just using the local notifications sample code – am I missing something?

[import]uid: 87249 topic_id: 36330 reply_id: 144425[/import]

As far as timers and lock screens, unless those are built by Apple or get special permission, the way they work is to detect that they have been suspended and save the time it was stopped. When they get a resume event, they start counting again adding the difference in time between the suspend and resume events.

Now the low battery warning I would think would suspend your app, but if it was running in the foreground, it should still be running in the foreground and you should get a regular suspend/resume set of events.

There are two parts to supporting this. First your app must not exit on suspend. This is a setting in build.settings. Next you have to setup a Runtime: listener for system events and have a function that responds to the suspend and resume events, stopping and restarting your timers accordingly.

[import]uid: 199310 topic_id: 36330 reply_id: 144350[/import]

I appreciate your response; however, I think you may have misunderstood. I do handle suspend/resume events without issue. The problem is, I don’t want the app to suspend at all when the battery warning appears (which it does), nor do I want it to suspend when the screen lock is activated. I don’t want the suspend event to fire. My app is designed to be ignored until an audio notification is triggered. If the app suspends, then the audio notification will not be triggered. I know this is possible natively with iOS code, but it seems impossible with Corona. [import]uid: 87249 topic_id: 36330 reply_id: 144367[/import]

It’s going to suspend when the device goes to sleep. Unless you are Apple and have access to backgrounding (using Objective C) that they don’t give to mortals, you’re not going to be able to stay live while the phone is locked/sleeping. There are a hand full of very specific things they let a sleeping app do which includes play music, check the GPS periodically, download newstand content, and a few others. See:

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

and click on the uiBackgroundModes link. If you’re not doing one of these, there is no running in the background or you’re Apple and can do what you want.

Apple is going to suspend your app on low battery warnings. There is nothing Corona Labs can do about this:

http://www.ios-developer.net/iphone-ipad-programmer/development/alert-view/system-alerts

Since you’re not Apple, the best thing you can do is to update your visual timer to account for the time the app was suspended.

You mentioned an audio alert… I don’t know if this is the same as playing music in the background or not. That is one of the things an app can continue to do, but I don’t know if that’s the case here.
[import]uid: 199310 topic_id: 36330 reply_id: 144369[/import]

Weird. Basically, my app displays a countdown timer, so there’s a timer running, and the display is updating, and when the countdown has completed, an audio file plays.

Here is an example of an iOS app that can do exactly that – Meditation Timer: https://itunes.apple.com/us/app/meditation-timer-free/id515571863?mt=8

It’s a free download – feel free to try it out. I’ve tested this particular app myself, and when the low battery alert happens, the alert still shows up on screen, but without vibration and you can still see the meditation timer counting down in the background. If you ignore the battery warning, the app still does its audio & vibration notifications. Also, this app will continue if the screen lock has been activated, and it will still provide its audio & vibration notifications. So it must be possible. This is exactly what I need my app to do.
[import]uid: 87249 topic_id: 36330 reply_id: 144376[/import]

I think they might be doing it with local notifications – that should take care of the screen lock issue. I wonder if it’ll work with the battery alert. I’ll give it a shot.

[import]uid: 87249 topic_id: 36330 reply_id: 144377[/import]

Using local notifications works well for when the screen is locked and the app is suspended. However, when the battery alert is displayed, the app is suspended; however, the notifications don’t seem to fire.

Actually, I’m having trouble getting the notifications to fire at all when the app is in the foreground – the notification listener fires, so I can handle that, but the notification alerts (audio, etc) don’t fire. Just using the local notifications sample code – am I missing something?

[import]uid: 87249 topic_id: 36330 reply_id: 144425[/import]

As far as timers and lock screens, unless those are built by Apple or get special permission, the way they work is to detect that they have been suspended and save the time it was stopped. When they get a resume event, they start counting again adding the difference in time between the suspend and resume events.

Now the low battery warning I would think would suspend your app, but if it was running in the foreground, it should still be running in the foreground and you should get a regular suspend/resume set of events.

There are two parts to supporting this. First your app must not exit on suspend. This is a setting in build.settings. Next you have to setup a Runtime: listener for system events and have a function that responds to the suspend and resume events, stopping and restarting your timers accordingly.

[import]uid: 199310 topic_id: 36330 reply_id: 144350[/import]