简体   繁体   中英

Push Notification In Mobile Web

Is it possible to receive notification on mobile devices whenever it's generated from the web Server.

This thing can be achieved by native apps for iPhone and Android. But my requirement is to achieve the same via a mobile website. Also is it possible to receive notification even if the user has closed the web browser.

It is possible to acheive, and you have 2 main ways to achieve this:

  1. WebSockets (HTML 5 required)
  2. HTTP long polling

Both methods require some trick server software, a good example is Socket.IO running on Node.JS platform.

Websockets require an HTML 5 browser (eg, Chrome) so might not work for your requirements.

HTTP long polling is the act of accepting an inbound HTTP connection on the server, and then sleeping until you wish to push the data to the client. Node.JS can be set to do this quite easily, or you could use Socket.IO (a library on Node.JS) which provides extra functionality. Socket.IO also works with Websockets where possible - and falls back to long polling if it has to.

In short, you will need a server platform to do this - I suggest you look at Socket.IO to start with. You can always roll your own once you have the main concept nailed. I wrote one in ASP.net which worked quite well, for example.

It is not possible to recieve notifications once the page in the browser ist closed. Notifications are triggered by apps running in the background of the smartphone os.

You can also use Server Sent Events (SSE) for this purpose. Android ICS supports SSE, if I am not wrong. HTML5 rocks (http://www.html5rocks.com/en/tutorials/eventsource/basics/) has an article on this and also point to a demo (http://googlecodesamples.com/html5/sse/sse.html).

However, none of these solutions (websockets, SSE) would be useful if you want your app to work in older Android devices as well. These solutions are not useful if you want to receive push when your app is not launched. The best solution is to build some sort of a hybrid app as suggested by richbayliss. I guess you do not really need phonegap for this. You can fire an event using loadDataWithBaseURL of WebView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM