标签:style http io ar color os 使用 sp 文件
MQTTKit在github上链接https://github.com/NormanLeeIOS/MQTTKit#send-a-message,down下来。
cd到工程目录,输入pod install,用xcode打开工程的打开xcworkspace扩展名的文件。如果不是MQTTKit存在更新的版本,则输入pod update。
2、连接过程
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"); }]; } }];
// 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]; } }];
[self.client disconnectWithCompletionHandler:^(NSUInteger code) { // The client is disconnected when this completion handler is called NSLog(@"MQTT client is disconnected"); }];
标签:style http io ar color os 使用 sp 文件
原文地址:http://blog.csdn.net/liyakun1990/article/details/41281789