Background Service in apache cordova app
Asked Answered
M

1

6

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.

Mainstay answered 13/9, 2014 at 21:50 Comment(0)
B
6

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.

Barnardo answered 14/9, 2014 at 8:17 Comment(1)
+1 for Background Fetch. The battery drain is negligible for a simple task I think. I would not rush into a push notification solution as it brings extra server-sided logic with it and also you depend on a 3rd party (Apple servers in this case) to deliver your content...Depersonalization

© 2022 - 2024 — McMap. All rights reserved.