setInterval in bg.js just dies without error

You must Login before you can answer or comment on any questions.

Hello folks,

I am still trying to establish a stable rss reader, that looks for new items in the RSS feed every few minutes. Therefore I register the background service and set an interval for my checker function.

var timer = setInterval(function(){
    getNewArticleCount();
}, 1000*60*1);
As a first thing in the getNewArticleCount() function I call an API Info, so I know the function has been called.

So far, so good. But after several minutes (about 7 to 9 Minutes) the interval just stops working. No error, no nothing.

Nov 22 15:43:36 unknown UIKitApplication:com.luehrsenheinrich.xxx[0xe9a1][6698] <Notice>: [INFO] >> Keepalive 1
Nov 22 15:44:36 unknown UIKitApplication:com.luehrsenheinrich.xxx[0xe9a1][6698] <Notice>: [INFO] >> Keepalive 2
Nov 22 15:45:36 unknown UIKitApplication:com.luehrsenheinrich.xxx[0xe9a1][6698] <Notice>: [INFO] >> Keepalive 3
Nov 22 16:07:49 unknown CommCenter[17] <Notice>: No more assertions for PDP context 0.  Returning it back to normal.
Nov 22 16:07:49 unknown CommCenter[17] <Notice>: Scheduling PDP tear down timer for (343667569.162510) (current time == 343667269.162536)
Nov 22 16:07:49 unknown CommCenter[17] <Notice>: Client [com.apple.persistentconnection[apsd,61]] is telling PDP context 0 to go active.
The fun thing is, no matter after how many minutes I resume the app (it does not crash!), Keepalive 4 is called just before resuming or at the same time. (The keepalive counts to 5 and then starts over with 1)

Anyone ever encountered a similar problem?

— asked 2 years ago by Hendrik Luehrsen
4 Comments
  • slightly confused why your doing 1000601 and not just 60000... Also to be honest keeping it running constantly may have strange effects.

    So maybe an option is to when you call getNewArticle you stop the interval ... Then when the data is returned you start it again. As it maybe something as simple as data errors or timeouts or clashes...

    T.

    — commented 2 years ago by Trevor Ward

  • I do the 1000601 just for easier reading. If i want to have 5 minutes i just change the 1 to 5.

    And with the cancellation and setting of the interval each time, wouldnt that be the sense of setTimeout?

    — commented 2 years ago by Hendrik Luehrsen

  • Yes pretty much.... As then it wouldn't continually loop on the interval and would basically just run when you have updated the data... Thus reducing the risk of any clashes...

    — commented 2 years ago by Trevor Ward

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!