내 나무 딸기 파이에서 데이터를 수신하는 응용 프로그램을 만들려고합니다. MQTT를 서버로 사용하고 있지만 메시지 수신 응용 프로그램을 만들려고하지 않을 때 작업. 나를 도와 줄 수있는 MQTT와 iOS 관련 경험이있는 사람이 있습니까?MQTT, iOS 신속 응용 프로그램 수신시 문제 발생
코드 :
import Moscapsule
class ViewController: UIViewController {
// set MQTT Client Configuration
let mqttConfig = MQTTConfig(clientId: "iOS Device", host: "192.168.178.27", port: 1883, keepAlive: 60)
mqttConfig.onConnectCallback = { returnCode in
NSLog("Return Code is \(returnCode.description)")
}
mqttConfig.onMessageCallback = { mqttMessage in
NSLog("MQTT Message received: payload=\(mqttMessage.payloadString)")
}
// create new MQTT Connection
let mqttClient = MQTT.newConnection(.mqttConfig)
// publish and subscribe
mqttClient.publishString("message", topic: "publish/topic", qos: 2, retain: false)
mqttClient.subscribe("subscribe/topic", qos: 2)
// disconnect
mqttClient.disconnect()
}
이 내가 My Xcode Project
이 MQTT와는 아무 상관 없다. 임의의 함수를 제외한 임의의 코드를 가지고 있으며 불필요한 코드를 가지고 있기 때문에 이것은 단지 구문 오류입니다. mqttConfig 앞에. 이 코드를'viewDidLoad'와 같은 함수로 옮겨야합니다. – Paulw11
왜 마지막에 disconnect를 호출할까요? MQTT 연결이 끊어 지므로 앱이 메시지를 수신하지 못합니다. –