Highlighted

Execute in background for more than 3 minutes?

Explorer ,
Apr 08, 2015

Copy link to clipboard

Copied

Hi,

My app is a timer-app. It works fine for 3 minutes in the background. If I set it to 5 minutes, it only works (in the background) for 3 minutes, then it stops. (it continues when I open the app again).

I believe there was a 10 minute "window" before, but now it's only 3? Is it possible to use beginBackgroundTaskWithExpirationHandler or something like that to ask for more time?

Apple only allows long-running background events for certain types of apps, e.g. background audio apps, like you noticed.

This type of situation would be better served with a local notification.    

TOPICS
Development

Views

2.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Execute in background for more than 3 minutes?

Explorer ,
Apr 08, 2015

Copy link to clipboard

Copied

Hi,

My app is a timer-app. It works fine for 3 minutes in the background. If I set it to 5 minutes, it only works (in the background) for 3 minutes, then it stops. (it continues when I open the app again).

I believe there was a 10 minute "window" before, but now it's only 3? Is it possible to use beginBackgroundTaskWithExpirationHandler or something like that to ask for more time?

Apple only allows long-running background events for certain types of apps, e.g. background audio apps, like you noticed.

This type of situation would be better served with a local notification.    

TOPICS
Development

Views

2.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 08, 2015 0
Explorer ,
Apr 09, 2015

Copy link to clipboard

Copied

I only tested in AIR 16 (16,0,0,252), but there it's definitely possible for a background worker to run for 5 minutes, at least on desktop. Are you testing on Android?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 09, 2015 0
Explorer ,
Apr 09, 2015

Copy link to clipboard

Copied

Forgot to write that it's on iOS. I've tried Air 16 to the latest 17 (release and beta). On my first version it did work for 5 minutes, but then I used "backgroundmode audio". But Apple said I had to remove it for my update, cause I couldn't play audio to keep a timer alive (I played a silent soundfile, and then an alarm sound when the timer was done. This worked fine, even if the app was in the background).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 09, 2015 0
Advocate ,
Apr 09, 2015

Copy link to clipboard

Copied

Adobe AIR * iOS Settings

Check section

Supporting background tasks on iOS

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 09, 2015 0
Explorer ,
Apr 10, 2015

Copy link to clipboard

Copied

I've tried a simple test with this code (Air 160.0.0.292, and iPod):

var timer:flash.utils.Timer = new flash.utils.Timer(1000); 
timer.addEventListener(TimerEvent.TIMER, timer_handler); 
timer.start()
function timer_handler( e:TimerEvent):void 
{
trace(timer.currentCount);
}

This works as expected, pauses when I send the app to the background.

With this:

NativeApplication.nativeApplication.executeInBackground = true;

It runs in the background for 180 seconds, and continues from 180 seconds when I open the app again.

With this:
var soundTest:Sound;
var soundChannelTest:SoundChannel;
soundTest = new Sound();
var reqTest:URLRequest = new URLRequest("5_minutes_test_sound.mp3");
soundTest.load(reqTest);
soundChannelTest = soundTest.play();

No audio when the app is sent to the background, timer works for 180 seconds.

With this in the -xml file:

<key>UIBackgroundModes</key> <array> <string>audio</string> </array>

The audio plays when I send the app to the background and the app doesn't stop after 180 seconds, but continues as long as I want it to.

Any tip, or is this a limitation from Apple? If Apple would allow "<key>UIBackgroundModes</key> <array> <string>audio</string> </array>"  for keeping the timer alive, then it would be fine, but they don't.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2015 0
Engaged ,
Apr 10, 2015

Copy link to clipboard

Copied

Apple only allows long-running background events for certain types of apps, e.g. background audio apps, like you noticed.

This type of situation would be better served with a local notification.    

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2015 0
Explorer ,
Apr 10, 2015

Copy link to clipboard

Copied

Thanks for the reply. I do have local notifications also, but let's say the timer is set for 5 minutes and the user open the app at 4 minutes (to check it's time), then it will continue from 3 minutes (although the local notifications will kick in at the right time).

I will let Apple remove my 5 minute timer, and I've already submitted an update for my 3 minute timer, which works.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2015 0
Engaged ,
Apr 10, 2015

Copy link to clipboard

Copied

That's a good point.  Is there a way to check, when the app resumes focus and has 1 minute left, when the local notification is set to go off, and adjust the time to match?

So a user starts a timer with 5 min, and goes away and comes back 4 min later.  The app looks at the local notification that's scheduled, sees there's only 1 minute left and adjusts its display accordingly.

I had always assumed that's how the timers worked in timer-based free-to-play games and in the native clock app, but I don't know for sure since I've never tried to code it for myself.    

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2015 0
Engaged ,
Apr 10, 2015

Copy link to clipboard

Copied

hey, thanks for marking my response as the answer btw. I'm a long-time lurker, trying to become a more active member of the community and post more, to give back to the community.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2015 0
Explorer ,
Apr 10, 2015

Copy link to clipboard

Copied

You're welcome I've never thought of using the local notifications like that, but it's interesting. Not sure if I would "force" the user to have the local nofitications active for the timer to work. I might try it out later.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2015 1
Engaged ,
Apr 10, 2015

Copy link to clipboard

Copied

I thought local notifications were on by default. Are they a privilege that needs to be granted?  And if so, are they separate from push notifications?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2015 0
gronli21 LATEST
Explorer ,
Apr 11, 2015

Copy link to clipboard

Copied

Push and local notifications both will present the user with a prompt asking for their permissions when the app starts. Local comes from the app itself, while push comes from a server. I believe with Xcode you could use something like "beginBackgroundTaskWithExpirationHandler" to ask for some extra time, which would be two minutes in my case, but I can't find out if it's supported by Air.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 11, 2015 0