当前位置:首页 > 操作系统 > Ios

关闭应用程序或关闭手机后,是否可以在Android / iOS应用程序上接收Pusher消息

关闭应用程序或关闭手机后,可以在Android / iOS应用程序上收到Pusher条消息吗?

我期望发生什么…

>手机开机时&应用程序已启动,从Pusher文档中可以很直接地了解如何对发送到该应用程序的pusher消息做出反应.
>手机开机时&应用已关闭,手机应收到一条通知,通知您已向该应用发送了一些东西.
>手机关闭时,手机重新打开后应会收到一条通知,通知已将某些内容发送到应用程序.

这些甚至可能吗?如果是,需要注意哪些建议?如果没有,有什么解决方法?

解决方法:

当使用Pusher的应用程序在iOS和Android上进入后台时,与Pusher的连接可能会保持活动状态几分钟.但是最终该连接将被关闭.您无法阻止这种情况在您的应用程序中发生(尽管在提交到Apps Store时可能会出现“黑客”的声音,表明您的应用程序是语音应用程序).

因此,您应该监视您的应用程序移至后台,并在不连接手机时将其放置在适当的位置以将消息传递到手机.

libPusher(Pusher iOS库)请参见How get pusher events when the iOS app go to the background?.

以下是Android Processes & Threads Lifecycle docs的“服务流程”摘录:

A process that is running a service that has been started with the startService() method and does not fall into either of the two higher categories. Although service processes are not directly tied to anything the user sees, they are generally doing things that the user cares about (such as playing music in the background or downloading data on the network), so the system keeps them running unless there’s not enough memory to retain them along with all foreground and visible processes.

因此,在这样的线程中运行Pusher实例是一个可行的选择.

但是,仍然会有用户离线的情况.在这种情况下,您可以通过querying the Pusher HTTP API或使用WebHooks来检测用户是否在线,从而可以立即通知服务器该用户是否脱机或重新联机.

使用上述机制,您可以简化smart notifications的工作;如果用户在线(应用程序在前台),则通过Pusher向其发送消息;如果用户离线(应用程序在后台),则使用其他传递方式(本机Push Notification,SMS或电子邮件) .


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!