emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.6k stars 420 forks source link

Retained message issue #575

Closed jerry20011024 closed 7 months ago

jerry20011024 commented 7 months ago

1.When i send retain message to a topic ,i get this message retained == false in didReceiveMessage 2.I have a retained message, but when I subscribe to a topic, the didReceiveMessage method is not being called. How can I correct this issue?

Issues mentioned above are not present when using the GUI. Everything works as expected.

jerry20011024 commented 7 months ago

I found Solution

 mqtt5.subscribe("xxx/power", qos: CocoaMQTTQoS.qos1)

to

 let power = MqttSubscription(topic: "xxx/power", qos: CocoaMQTTQoS.qos1)
 power.retainHandling = .sendOnSubscribe
 power.retainAsPublished = true
 power.noLocal = false
 mqtt5.subscribe([power])