Hi there -- what's the proper way to use backgrounding in iOS and avoid these types of forced crashes:
Mar 7 16:32:41 unknown SpringBoard[70] <Warning>: app[4044] has active assertions beyond permitted time: {( <SBProcessAssertion: 0x105b75b0> identifier: UIKitBackgroundCompletionTask process: app[4044] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:4044 preventSuspend preventIdleSleep , <SBProcessAssertion: 0x103ec500> identifier: UIKitBackgroundCompletionTask process: app[4044] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:4044 preventSuspend pre...I have this in my app.js:
var service = Titanium.App.iOS.registerBackgroundService({ url: 'backgroundservice.js' });and in backgroundservice.js I have this:
Ti.API.info('Background service started'); // now unregister it in 590 seconds (under 600 to be safe!) var stopTimeout = setTimeout(function() { stopTimeout = null; Ti.API.info('Background service stopping...'); Ti.App.currentService.stop(); Ti.API.info('Background service stopped!'); }, 590 * 1000); Ti.App.currentService.addEventListener('stop', function() { if(stopTimeout) { clearTimeout(stopTimeout); } Ti.API.info('Background service stopped automatically!'); });Should I put an "unregister" somewhere do avoid crashes? (I DO want it to always go in the background, and allow background stuff to happen -- like finishing file uploads, etc.)
Thanks for your help in advance!
1 Answer
Accepted Answer
Try this:
Ti.API.info('Background service started'); // now unregister it in 590 seconds (under 600 to be safe!) var stopTimeout = setTimeout(function() { // stopTimeout = null;//--- TODO: Change here Ti.API.info('Background service stopping...'); Ti.App.currentService.stop(); Ti.API.info('Background service stopped!'); }, 2000); Ti.App.currentService.addEventListener('stop', function() { if(stopTimeout) { clearTimeout(stopTimeout); stopTimeout = null; } Ti.API.info('Background service stopped automatically!'); });
Your Answer
Think you can help? Login to answer this question!