iOS XMPP 在后台断开连接不会被报告
当应用程序在后台运行并且 xmpp 由于互联网中断而断开连接时,如果互联网恢复正常,当我打开应用程序时,不会进行断开连接调用,因此应用程序不会尝试重新连接。
如果我检查 xmppstream 是否已连接,它显示为“是”。当我返回应用程序时,如何检查连接是否仍然有效?
目前我正在尝试断开连接,并在每次应用程序唤醒时连接。但理想的是检测断开连接...
谢谢
When the app is in the background and xmpp disconnects because the internet goes down, and if the internet comes back up, when I open the app, the disconnect call is not made so the app doesn't try to reconnect.
If i check the xmppstream is connected it shows as Yes. How can I check if the connection is still alive when I go back to the app?
Currently I am trying a disconnect, and connect each time the app wakes up. But ideal would be to detect disconnection...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以检测到应用程序何时唤醒,请发送 ping。如果没有收到回复,请重新连接。如果您使用的 XMPP 库支持流管理,特别是流恢复支持,您可以用它来拾取流。
更好的解决方案是使用一个单独的守护进程来管理连接,并在后台保持活动状态(如果 iOS 允许的话)。另外,这个 XEP 可能会引起兴趣。
If you can detect when the app wakes up, then send a ping. If you don't get a reply, reconnect. If the XMPP lib you use has support for Stream Management, especially the stream resumption support, you could use that to pick up the stream.
A better solution would be to have a separate daemon that manages the connection, and stays alive in the background, if that's even allowed on iOS. Also, this XEP might be of interest.
如果您使用的是 XMPPFramework (https://github.com/robbiehanson/XMPPFramework),那么请查看 XMPPReconnect,这将为您省去很多重新连接的麻烦。
创建流后,使用以下命令。
If you're using XMPPFramework (https://github.com/robbiehanson/XMPPFramework), then take a look at XMPPReconnect, which will save you a lot of the hassle of reconnecting.
After the stream has been created, use the following.