iosswiftmqttios-mqtt-client-framework

iOS MQTT do not receive message after reconnection


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?


Solution

  • Fixed myself by changing the clean session flag to false Do not need to unsubscribe the topic