简体   繁体   English

为桌面应用推送通知?

[英]Push notifications for desktop apps?

Push notifications for mobile apps allow for some cool possibilities in terms of user experience.移动应用程序的推送通知在用户体验方面提供了一些很酷的可能性。 Are similar services available for desktop apps, such as those written in Java or C#?是否有类似的服务可用于桌面应用程序,例如用 Java 或 C# 编写的应用程序?

My goal is to let the program take actions based on notifications from a server.我的目标是让程序根据来自服务器的通知采取行动。 If push notifications aren't available, what are some workarounds I could do?如果推送通知不可用,我可以采取哪些解决方法? Have the program schedule itself as a task (either a cron job, or scheduled task, or w/e), then check the server for updates?让程序将自身安排为一项任务(cron 作业、计划任务或 w/e),然后检查服务器是否有更新? Keeping the program running in the background at all times wouldn't be an option, because updates would be too infrequent.让程序始终在后台运行不是一种选择,因为更新太少了。

If you want push notifications, you don't have much choices other than having a process running at all times because the server would need a way to contact your application. 如果您想要推送通知,除了让进程始终运行之外,您没有太多选择,因为服务器需要一种联系您的应用程序的方法。

Using push notifications, you can either have a permanent connection with the server with sockets for example. 使用推送通知,您可以与具有套接字的服务器建立永久连接。 When there is an update, the server would notify your application and you do whatever needs to be done. 当有更新时,服务器会通知您的应用程序,您可以做任何需要完成的事情。

However, if your updates are infrequent, a pull solution might be a better idea, because it wouldn't require a permanent connection. 但是,如果您的更新很少,那么拉出解决方案可能是个更好的主意,因为它不需要永久连接。

Since your program doesn't need to be open all the time, 由于您的程序不需要一直打开,

(Have the program schedule itself as a task (either a cron job, or scheduled task, or w/e), then check the server for updates? Keeping the program running in the background at all times wouldn't be an option, because updates would be too infrequent.) (让程序将自己安排为任务(cron作业,计划任务或w / e),然后检查服务器是否有更新?保持程序在后台运行始终不是一个选项,因为更新太少了。)

you might just want to check with the server if an update is available at application startup (depending on your needs, hard to tell only with details from the question). 您可能只想检查服务器是否在应用程序启动时有可用的更新(根据您的需要,很难仅通过问题的详细信息来说明)。

If you want, you might also add polling the server in a background thread wich checks for updates at a fixed interval (one that fits your needs). 如果需要,您还可以在后台线程中添加轮询服务器,后台线程会以固定的时间间隔(符合您的需求)检查更新。

You could just use a Push/Subscription service like Pusher (or implement it your self). 您可以使用像Pusher这样的推送/订阅服务(或者自己实现)。

With Pusher you could just have an app, server, or anything that pushes an event and have the clients to be subscribed to Pusher for the specific event type, and then when the event arises it is notified to the clients. 使用Pusher,您可以拥有一个应用程序,服务器或任何推送事件的东西,并让客户订阅Pusher以获取特定的事件类型,然后当事件发生时,它会通知客户端。

Since this question was originally asked, more options have become available.由于最初提出此问题,因此有更多选项可用。 Now the Windows App SDK offers Push Notifications .现在,Windows 应用程序 SDK 提供推送通知 This enables:这使:

Application Wakeup - Push notifications can be used to wake up your application instead of it having to be constantly running which frees up user resources.应用程序唤醒 - 推送通知可用于唤醒您的应用程序,而不必一直运行,从而释放用户资源。

Real Time Sync - Push notifications can replace polling scenarios for your applications by sending push notifications to your clients and notifying them to sync with your web service实时同步 - 推送通知可以通过向您的客户端发送推送通知并通知他们与您的 Web 服务同步来代替您的应用程序的轮询方案

This also makes it unnecessary to have persistent connections.这也使得没有持久连接成为必要。 This is made possible by Windows Push Notification Services (WNS).这是通过Windows 推送通知服务 (WNS) 实现的。 Equivalent services exist for other platforms:其他平台存在等效服务:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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