How to keep the app in the background after closing - PhoneGap - javascript

I would keep my PhoneGap application in background after closing it in order to generate notifications.
I wish my application available on iOS , Android and Windows Phone with notifications.
Is it possible to execute the JavaScript when the application is in the background ?
How to do ?

On iOS there are two kinds of notifications - remote notifications and local notifications. Remote notifications are delivered by your webservice through APNS and require for the device to be connected to the internet.
Local notifications on the other hand are scheduled on device. The most important thing is that both will wake your app for a short time, so it can consume the notification and decide what to do with it. During this time you can of course schedule another local notification.
This - https://github.com/katzer/cordova-plugin-local-notifications - seems like a good place to start investigating.

Related

Is there a way to keep my React JS PWA (Progressive Web App) running in background?

I coded a Chatting App and a Alarm clock App in React Js and they're working fine in foreground (while the apps are opened on screen). But I need a way to keep them running in the background to check for latest messages or to play the alarm sound. (Like clock app in phone or WhatsApp/Facebook)
Does anyone has solution?
I can't seem to find any solution, either by myself or Internet.
If you are targeting mobile devices, the best solution you have is to run a service worker, which can execute code in the background and show notifications. There are limits to the APIs available to a service worker, so playing a sound might not be possible.

Progressive web apps and Web socket connections in background

What should be the expected behavior when I add my webpage to home on Android device and my page contains a websocket connection. Should it still gets updates even in the bakground?
Based on my quick demo, it stops receiving updates when in the background. Also i dont have a service worker hooked up yet, its just opens up in full screen as a pwa.
Service Workers live for a limited amount of time (on the order of 5 minutes). They can not maintain persistent connections like WebSockets.

How to know if web app and executable app both are active at same time

I have a web app something like slack which is used for chatting and when user is offline then we send the notification that "you have a new message". The notification is html5 push notification, so it works when user has not opened web app.
I have recently created an executable app for people who chat all day. But problem is that when a new message is coming : notification coming from exe app and browser both.
So my question is : Can we find if web app and exe app both are active in one device? So that we can supress one of the notification. Does a pc have something like common id which we can access from javascript in browser and executable too?
Note :- I have information stored in server that web app is active and exe is active, i only need to find if they are from same device.
Thanks in advance. Please let me know your solution.
After a lot of hit and trial with different solutions - I found a solution.
I am embedding a http server in the exe app which let me communicate with web app. In the web app, i have added a web worker, which will ping the exe app server every 10 sec. If response received means exe app is active, then i turn off the notification on server by calling api. This will also make sure when the exe app is quitted, web worker wont get any response means exe is not active, so it activates the notification.
Now another issue was that - after installing the app, user didn't open the web app and he is getting two notification still. For overcoming this - i open the web app url when the exe app starts for the first time and it detects the status and turn off the browser notification. In the same process - i also save the browserId (a unique guid to identify the browser ) to the exe app and whenever exe app starts, i call the api to turn off the notification for these browserId.
Hope this helps someone.

how facebook created push notification when its web app is closed

Recenlty I've notice that I get push notifications from facebook even that I don't have facebook app open. How is that possible?
This is done using the Push API which builds off the ServiceWorker API which allows web applications to register long-lived background services that outlive a specific website visit. As to how this is implemented, even if the browser/website is not in the foreground, there is an application running in the background or there is a handler registered to start/resume the background application when an event is received. Android services enable this under-the-hood.
I think Using push notifications...In mobile computing is that the technology doesn't require specific applications on a mobile device to be open in order for a message to be received. This allows a smartphone to receive and display social media or text message alerts even when the device's screen is locked and the social media application that is pushing the notification is closed.

Push Notification function on Phonegap app using javascript

I am building a push notification on Phonegap. I reviewed the way of using the Push Plugin but it is not supporting windows phone. I plan to use Javascript non stop looping by every 15 mins to query the Rest server and get the message back to display if any message is ready to published. Do you think this is a good idea? Will this cause any app leaking and slow down the app?
You will shoot yourself in the foot doing so.
Why? Your app will only be able to "receive" push notifications if it is active. If your app is inactive, you won't be able to poll for new notifications and therefore won't get any. So you're missing the actual great benefit of push notifications.
Solution: Pull the new version of the Cordova Push Notifications Plugin. Support for Windows Phone 8 was added recently. That's the way to go.

Categories