Page 1 of 1

Run JS when app in background

Posted: Sat Apr 04, 2015 4:55 pm
by JimmyH

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


Run JS when app in background

Posted: Sat Apr 04, 2015 5:31 pm
by Illya Stepanov

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/...


Run JS when app in background

Posted: Sat Apr 04, 2015 7:04 pm
by JimmyH

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


Run JS when app in background

Posted: Sat Apr 04, 2015 9:58 pm
by Evgene Karachevtsev

Hello James,

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


Run JS when app in background

Posted: Sun Apr 05, 2015 5:08 am
by JimmyH

Hi evgene,

That is correct.
Thanks


Run JS when app in background

Posted: Tue Apr 07, 2015 5:22 pm
by JimmyH

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


Run JS when app in background

Posted: Tue Apr 07, 2015 6:53 pm
by JimmyH

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


Run JS when app in background

Posted: Wed Nov 04, 2015 8:50 am
by ben7812677

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...