在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:mobile-web-messaging/MQTTKit开源软件地址:https://github.com/mobile-web-messaging/MQTTKit开源编程语言:C 87.9%开源软件介绍:MQTTKitMQTTKit is a modern event-driven Objective-C library for MQTT 3.1. It uses Mosquitto 1.2.3 library. An iOS application using MQTTKit is available at MQTTExample. Project StatusThis project is no longer maintained (some context about this decision). If you encounter bugs with it or need enhancements, you can fork it and modify it as the project is under the Apache License 2.0. Installation Using CocoaPodsOn your
For the first time, run UsageImport the #import <MQTTKit.h> Send a Message// create the client with a unique client ID
NSString *clientID = ...
MQTTClient *client = [[MQTTClient alloc] initWithClientId:clientID];
// connect to the MQTT server
[self.client connectToHost:@"iot.eclipse.org"
completionHandler:^(NSUInteger code) {
if (code == ConnectionAccepted) {
// when the client is connected, send a MQTT message
[self.client publishString:@"Hello, MQTT"
toTopic:@"/MQTTKit/example"
withQos:AtMostOnce
retain:NO
completionHandler:^(int mid) {
NSLog(@"message has been delivered");
}];
}
}];
Subscribe to a Topic and Receive Messages// define the handler that will be called when MQTT messages are received by the client
[self.client setMessageHandler:^(MQTTMessage *message) {
NSString *text = [message.payloadString];
NSLog(@"received message %@", text);
}];
// connect the MQTT client
[self.client connectToHost:@"iot.eclipse.org"
completionHandler:^(MQTTConnectionReturnCode code) {
if (code == ConnectionAccepted) {
// when the client is connected, subscribe to the topic to receive message.
[self.client subscribe:@"/MQTTKit/example"
withCompletionHandler:nil];
}
}]; Disconnect from the server[self.client disconnectWithCompletionHandler:^(NSUInteger code) {
// The client is disconnected when this completion handler is called
NSLog(@"MQTT client is disconnected");
}]; Authors |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论