JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Run JS when app in background

Hi there,

I would like to run a java script (involves geolocation and other things) when the app is in the background. I have tried the setinterval function but this doesn't seem to work.

Do I need to add a plugin (eg. cordova-plugin-background-mode) etc?

Your help would be much appreciated.

Thanks
James

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Run JS when app in background

Hi James -

I'm not sure if the JavaScript code will run in the background as this mostly depends on mobile OS permissions.

But you can try this Cordova plugin and before using it check this conversation on Stackoverflow -- http://stackoverflow.com/questions/26...

and this post on our forum: https://getsatisfaction.com/apperyio/...

JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Run JS when app in background

Hi Illya,

Thanks very much for your prompt response.

I have reviewed the the links provided.

I had originally wanted to use a push notification to trigger the app to run the script, but the "Push Notification" event did not seem to work (ie did not fire event). Is there something specific that I need to do get trigger the event with a push notification? I have read various topics etc.

What i am hoping to achieve is:

  1. push notification to trigger script

  2. a service executed (involves geolocation) from within the script.

  3. a value is returned and is presented to the user via a local notification.

    I reported a bug associated with step 1 (http://gsfn.us/t/4pinb) and consequently was trying a different approach (as I did not want the push notification to be visible to the user). though the steps above are my preferred way of doing it.

    thanks
    james

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Run JS when app in background

Hello James,

Sorry, do I understand you correctly that push is sent successfully, but event inside the app never fires?

JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Run JS when app in background

Hi evgene,

That is correct.
Thanks

JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Run JS when app in background

Hi Evgene,

I have tried again and it still still doesn't work. I can send the push notification successfully, but the event does not trigger inside the app.

I have also created a simple test app and the problem occurs here as well.

thanks
James

JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Run JS when app in background

Hi Evgene,

I have just re-tested and it now seems to be working. I didn't change anything at my end so I'm not sure what happened. It might be related to the issue reported here http://gsfn.us/t/4pinb . Either way it is working

thanks
James

ben7812677
Posts: 0
Joined: Wed Oct 14, 2015 12:22 pm

Run JS when app in background

JimmyH - any idea how you got this 'push notification' event to fire properly when the app is in background or lock screen? I'm having the same problem and not getting much joy...

Return to “Issues”