Jim*_*Pun 5 ios mqtt swift ios-mqtt-client-framework
我正在使用MQTT-Client-Framework开发iOS应用程序。该应用程序在首次启动时成功与服务器通信。
但是,当我将其设置为后台并返回到前台后,我不再从MQTT服务器接收任何消息。
每当应用程序退出活动并变为活动状态时,我都会使用一个新Mqtt对象(不同的客户端ID)进行重新连接:
func applicationWillResignActive(_ application: UIApplication) {
//Unsubscribe topic, disconnect the mqtt client, and close the client
}
func applicationDidBecomeActive(_ application: UIApplication) {
//Renew mqtt client, set delegate, reconnect to server and subscribe topic
}
Run Code Online (Sandbox Code Playgroud)
但是,重新连接后,我不再从服务器收到任何消息。我检查了客户端状态,并且它已连接。重新连接后如何使应用程序接收消息?
| 归档时间: |
|
| 查看次数: |
362 次 |
| 最近记录: |