Closed zzsqwq closed 8 months ago
Hello. you can try to set properties in subscribe. Here are some examples.
let topic = MqttSubscription(topic: "chat/room/animals/client/+")
let subscriptions : [MqttSubscription] = [topic]
topic.retainHandling = CocoaRetainHandlingOption.sendOnSubscribe
mqtt5.subscribe(subscriptions)
Base on this article, I think the retainHandling setting in the subscription options should be set to default to .sendOnSubscribe
instead of .none
to maintain compatibility with the MQTT3.1.1 default behavior.
Hello, I am recently using the CocoaMQTT library to subscribe to and publish topics. The specific usage is as follows, but I noticed that I cannot receive any retained messages, but using MQTTX can be received normally.
In my example, there is a retained message on
qyun/robot/QYUN-Q03-0001/info/ip
. I should receive the relevant message after subscribing to the topic when the App starts, and print logdidReceiveMessage is retained message
, but no message was received. But I can be sure that the topic is successfully subscribed, because if I send a message to the topic after the app is started, it can be received normally, but the message received is not a retained message.What could possibly be the problem? Thanks.
Retained message:
Code: