简体   繁体   English

当应用程序在后台时,如何在IOS应用程序中保持XMPP连接活动?

[英]How to keep XMPP connection alive in the IOS App when app in background?

I have create basic chat app with XMPP Server in swift 2 (from this tutorial: http://shubhank101.github.io/iOSAndroidChaosOverFlow/2016/08/Chat-Application-Using-XMPP-Swift-Tutorial ). 我在swift 2中使用XMPP Server创建了基本的聊天应用程序(来自本教程: http://shubhank101.github.io/iOSAndroidChaosOverFlow/2016/08/Chat-Application-Using-XMPP-Swift-Tutorialhttp://shubhank101.github.io/iOSAndroidChaosOverFlow/2016/08/Chat-Application-Using-XMPP-Swift-Tutorial )。 My app is working good. 我的应用程序运行良好。 but when my app went into background then my app unable to receive any message from XMPP server. 但是当我的应用程序进入后台时,我的应用程序无法从XMPP服务器接收任何消息。 i think this is because of XMPP connection break while entering the app in background. 我认为这是因为在后台进入应用程序时XMPP连接断开。

i have tried to found the help on google for the same but nothing found related to Swift 2 我试图在谷歌找到相同的帮助,但没有发现与Swift 2

Please help me. 请帮我。 if some one put some sample code that would very helpfull for me because im new to IOS development. 如果有人给我一些非常有用的示例代码,因为我对IOS开发很新。

You need to create a background thread to maintain XMPP connection. 您需要创建后台线程以维护XMPP连接。 You can follow this tutorial to see how background thread works. 您可以按照本教程查看后台线程的工作原理。 https://thatthinginswift.com/background-threads/ https://thatthinginswift.com/background-threads/

Third-party apps on the iOS are not allowed to keep network connection in background. iOS上的第三方应用程序不允许在后台保持网络连接。 See Apple guidelines how to avoid background networking. 请参阅Apple指南,了解如何避免后台联网。

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

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