프로젝트
GitHub에서 보기
mobile-web-messaging/MQTTKit
소개
iOS용 MQTT Objective-C 클라이언트
시스템 및 인프라측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalMQTTKit
MQTTKit 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 Status
This 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 CocoaPods
On your Podfile add this project:
...
pod 'MQTTKit', :git => 'https://github.com/mobile-web-messaging/MQTTKit.git'
...
For the first time, run pod install, if you are updating the project invoke pod update.
Usage
Import the MQTTKit.h header file
#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
관련 프로젝트 살펴보기
불러오는 중…