要运行示例项目,请克隆仓库,并从 Example 目录首先运行 pod install
。
-(void) connect {
mqttClient=[[MqttClientEx alloc] initWithClientId:@"some_unique_id"];
mqttClient.host=MQTT_SERVER;
mqttClient.username=MQTT_USERNAME;
mqttClient.password=MQTT_PASSWORD;
[mqttClient connectWithCompletionHandler:^(MQTTConnectionReturnCode code) {
NSLog(@"mqtt is connected");
mqttClient.keepAlive = 0;
[[NSNotificationCenter defaultCenter] postNotificationName:MQTT_CONNECTED object:nil];
}];
mqttClient.disconnectionHandler=^(NSUInteger code)
{
NSLog(@"mqtt is disconnected");
};
}
-(void) example {
[mqttClient subscribe:@"a" withTag:@"tag1" wittMessageHandler:^(MQTTMessage *message) {
} withCompletionHandler:nil];
[mqttClient subscribe:@"a" withTag:@"tag2" wittMessageHandler:^(MQTTMessage *message) {
} withCompletionHandler:nil];
}
-(void) stop {
mqttClient.keepAlive = 0;
}
MqttEx 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中
pod "MqttEx"
xuwq, [email protected]
MqttEx 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。