简体   繁体   English

将通知推送到我的应用而非用户

[英]Push Notification to my app not the user

I want to notify my app that there is new data available but I do not want my app to constantly polling my server = checking for it new user data wasting user data and killing the users battery. 我想通知我的应用程序有可用的新数据,但我不希望我的应用程序不断轮询服务器=检查它是否有新的用户数据浪费用户数据并耗尽用户电量。

Instead it would be nice to send a message to my app letting it know there is new data ready to consume. 相反,最好将一条消息发送到我的应用程序,让它知道有随时可以使用的新数据。

Just don't register for alerts then the user won't get the alerts when the app isn't open but if the app is open you can still respond to notifications silently or how you choose. 只是不注册警报,那么当应用程序未打开时用户将不会收到警报,但是如果应用程序处于打开状态,您仍然可以静默响应通知或选择方式。

Or: (this will save yours and users bandwidth) 或者:(这将节省您和用户的带宽)

When the app closes send a message to your server telling it that the app is closed and not to send new notifications. 当应用程序关闭时,向您的服务器发送一条消息,通知它该应用程序已关闭,并且不发送新的通知。 Then when the app starts send a message to the server telling it to send notifications. 然后,当应用程序启动时,向服务器发送一条消息,告诉它发送通知。

EDIT: unless you want to have the app open automatically or download the new content in the background, in which case that isn't possible. 编辑:除非您想让应用程序自动打开或在后台下载新内容,否则是不可能的。

这不是默认行为吗?只要有新数据,推送通知服务器就会通过回调通知您的应用程序。

You can open socket to your server an d make it listen for data - this option will drain user battery, maybe not so fast as frequent HTTP requests. 您可以打开服务器的套接字并使其监听数据-此选项将耗尽用户的电量,可能不如频繁的HTTP请求快。 Also you can try do those HTTP request, but make them as long-poll. 您也可以尝试执行这些HTTP请求,但是将其设置为长轮询。 For example application will request some URL and server will hold that connection for specific amount of time or response something is there is data available for the user. 例如,应用程序将请求一些URL,服务器将在特定时间内保留该连接,或响应某些内容,该数据可供用户使用。 When connection closed, your application should reopen it. 关闭连接后,您的应用程序应重新打开它。

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

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