简体   繁体   English

重新连接后,iOS MQTT不会收到消息

[英]iOS MQTT do not receive message after reconnection

I am developing an iOS application using MQTT-Client-Framework. 我正在使用MQTT-Client-Framework开发iOS应用程序。 The app successfully communicates with the server at the first launch. 该应用程序在首次启动时成功与服务器通信。

But after I turn it to background and get back to foreground, I no longer receive any message from the MQTT server. 但在我将其转为后台并返回前台后,我不再收到来自MQTT服务器的任何消息。

Everytime the app resign active and become active, I will do the reconnection with a new Mqtt object (different client ID): 每次应用程序重新激活并变为活动状态时,我将使用新的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
}

However, I no longer receive any message from server after the reconnection. 但是,重新连接后,我不再收到来自服务器的任何消息。 I checked the client status, and it is connected. 我检查了客户端状态,并且已连接。 How can I make the application receive message after reconnection? 重新连接后如何让应用程序接收消息?

通过将clean session标志更改为false来修复自己。不需要取消订阅该主题

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

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