Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Service in apache cordova app

I need to poll a server in a given interval with on a Apache Cordova app and notify the user if there is relevant information for him/her. I'm not sure if it could be done with webworkers because the event (server poll) also has to happen when the application is inactive in iOS and Android.

Has anyone faced a similar issue?, I've looked into local noifications/dialogs to deliver the message, but I'm unsure of how to create the polling service.

Thanks in advance.

like image 490
Tristian Avatar asked Sep 13 '14 21:09

Tristian


1 Answers

In my eyes permanent polling is never a good solution. I would advice you to use Push, so your server notifies the app as soon as there is new content available. It saves a lot of battery on your device, because it is only woken up if there really is an update. The Push Notification Services are built for exactly this purpose.

Have a look at the excellent Push Plugin for Phonegap, which works for iOS, Android and even more platforms. For setting up the Push Plugin for iOS and Android you can read Holly Schinsky's tutorial here.

In Ray Wenderlich's tutorial here you find information about how you could implement the server side described in great detail.

If you really want to stick with polling, I know there is the possibility to do so on iOS (see this article about Background Fetch), not sure about Android (I guess you would need to implement a Service there). However, I never found a Phonegap plugin which handles background execution for both platforms accordingly.

like image 163
qefzec Avatar answered Nov 11 '22 17:11

qefzec