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.
Related
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.
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.
Is it possible to keep a html 5 web pages WebSocket connection open in Mobile-Safari once the screen is locked?
I want to send my users continuous updates throughout the day and it seems silly that their screens should always have to be unlocked to receive those notifications.
Are there any other options?
I don't think it's possible to keep the connection open while the browser is in the background, or when the screen is locked, the reason being that the app is essentially frozen in memory. Here's a quote from a similar question:
the reason you cant keep a network socket open, is that without your app jumping to the foreground when it receives a connection, it cannot respond to network traffic(because if it is not in the foreground its memory content is frozen).
However, I did find this page on Push Notifications for Websites that shows you 'how to sign up your users to receive notifications even when your site is not running in Safari'.
There are some other options: if you want to send continuous updates, you could write an app and either follow the instructions on Apple's site to keep a socket open permanently, or you could configure the app to implement Push Notifications.
I'm sorry I couldn't find a quick fix, but I hope at least one of these options works for you!
I have found a hacky way to keep WebSocket alive in Mobile Safari.
Basically it's the same solution as for this question.
Create an infinity looping audio file to keep Javascript running:
<audio loop src="http://www.sousound.com/music/healing/healing_01.mp3"></audio>
Note: some user interaction is required to initiate the audio file.
It would be nice if a WebSocket kept the browser alive in the same manner as an audio or video file.
PS this also works on Android.
I am working with a website having a chat functionality (think Facebook chat).
I'd like to play a notification tone when a new message arrives. However, the user may have multiple tabs opened and the message arrives to the multiple tabs, as the chat session is multiplexed across different browser tabs/windows.
How to determine
If a browser has many tabs (windows) open for the same website
When a new message arrives which of the tab(s) should play a sound effect
I am aware of the Notifications API, but I'd like to solve this problem in backwards-compatible manner. Also if there are any related JavaScript libraries I would like to know about them.
You can use localStorage for such purposes. Data in localStorage is shared between all windows (tabs or iframes) with the same origin. It also can notify your application about changes in localStorage.
See IWC library. I think it will help with your tasks.
I am developping an app for Ipad (2 and 3).
The app needs a continuous synchronization with a remote web app. Point is, my app needs to keep "listening" whenever there is connectivity in order to receive updates (lots of data), alerts,... etc.
PS: Before going further I would like to highlight that my app is not targeted to the appstore and moreover it can't rely on push notifications.
What I am confused about is the multitasking on the ipad. I would like my app's local db to stay synchronized by communicating with the remote web app. And hence my questions are:
Does any of the ipads have a real multitasking? (like android's where you can have "services") Meaning that my app or at least a small part of it would still operate even if it is not active on the screen.
How can I achieve that using phonegap standard framework?
If the above points show that at some extent it's not possible. Is there still a possibility to extend phonegap with a plugin and make this happen?
If the above three points are unfortunately fully negative; how would you address the problem by keeping in mind that the syncrhonization involves a lot of data and is mandatory to cover the app's usability?
Does any of the ipads have a real multitasking? (like android's where
you can have "services") Meaning that my app or at least a small part
of it would still operate even if it is not active on the screen.
IOS only has limited background services - in that your app goes into a background state when not active. Really only limited to receiving push notifications. As Phonegap uses a webview and javascript that is only active when the app is active in the foreground.
How can I achieve that using phonegap standard framework?
If you want to keep data connection open you might have to look at development of an application for a computer tablet, rather then an IOS device.
If the above points show that at some extent it's not possible. Is
there still a possibility to extend phonegap with a plugin and make
this happen?
No.
If the above three points are unfortunately fully negative; how would
you address the problem by keeping in mind that the syncrhonization
involves a lot of data and is mandatory to cover the app's usability?
You only option (if you can only use phonegap) is to have the app active all the time, and set a constant sync using Jquery & XML/JSON data. Of course this depends on what type of data you are going to show. For showing a page of data - similar to a webpage you won't have any problems - as long as you understand once you change apps that data won't be synced.
I would like my app's local db to stay synchronized by communicating with the remote web app.
If I were you, I'd be questioning why would I need to do that? Why not just make the app works online? You can have all the assets locally, and just setup some sort of API to retrieve whatever data you need to display on demand.
Otherwise, you'll need to hack your way through to do all the things you wanted, plus you need offline / online syncing. Since you have most data available offline, I assume the app also works offline? And you'll have a really bad time working on offline / online syncing...