flightonary/Moscapsule

About onMessageCallback

kelly08385 opened this issue · 1 comments

I want subscribe some message by mqtt
but the program didn’t do this block

mqttConfig.onMessageCallback = { mqttMessage in
// write received message to log
NSLog("MQTT Message received: payload=(mqttMessage.payloadString)")
}

until I add dispatch_main() after mqttClient.publishString , it can work.
But it let the program only do onMessageCallback , how to stop it?
——————————————————————————
If I didn’t add dispatch_main()
the message is show above

2016-04-13 09:23:07.381 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending CONNECT
false
2016-04-13 09:23:07.382 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0)
2016-04-13 09:23:07.382 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending PUBLISH (d0, q0, r1, m2, 'topic123', ... (7 bytes))
2016-04-13 09:23:07.382 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending DISCONNECT

It didn’t print any callback message.
What is the problem?
ps. I didn't write mqttClient.disconnect() in my code.

Does it have any example?
ps. sorry for my poor English, if you have any question, please tell me, thanks!

The question is similar to this website http://social.gseosem.com/stackoverflow/how-to-create-a-persistent-mqtt-connection-to-mosquitto-with-moscapsule/

@kelly08385 if you resolve this problem ?
Because I have the same issue and can't find any solution how to fix it.