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

时间:2017-01-27 07:03:27

标签: ios swift mqtt 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
}

但是,重新连接后,我不再收到来自服务器的任何消息。我检查了客户端状态,并且已连接。重新连接后如何让应用程序接收消息?

1 个答案:

答案 0 :(得分:1)

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