I am developing an iOS application using MQTT-Client-Framework. 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.
Everytime the app resign active and become active, I will do the reconnection with a new Mqtt
object (different client 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来修复自己。不需要取消订阅该主题
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.