洞察探索如何利用兼容微信生态的小程序容器,实现跨平台开发,助力金融和车联网行业的数字化转型。
1250
2022-10-22
MQTT-Client-Framework 是Objective-C原生MQTT框架
MQTT-Client-Framework is a native Objective-C iOS library. It uses CFNetwork for networking and CoreData for persistence. It is a complete implementation of MQTT 3.1.1 and supports TLS.
You can read introduction to learn more about framework.
MQTT-Client-Framework is tested with a long list of brokers:
mosquittopahorabbitmqhivemqrsmbmoscavernemqemqttmoquetteActiveMQApolloCloudMQTTawshbmqtt (MQTTv311 only, limitations)aedesflespi
Usage
For example app, see MQTTChat
Create a new client and connect to a broker:
#import "MQTTClient.h"MQTTCFSocketTransport *transport = [[MQTTCFSocketTransport alloc] init];transport.host = @"test.mosquitto.org";transport.port = 1883; MQTTSession *session = [[MQTTSession alloc] init];session.transport = transport;[session connectWithConnectHandler:^(NSError *error) { // Do some work}];
Subscribe to a topic:
[session subscribeToTopic:@"example/#" atLevel:MQTTQosLevelExactlyOnce subscribeHandler:^(NSError *error, NSArray
In your MQTTSession delegate, add the following to receive messages for the subscribed topics:
- (void)newMessage:(MQTTSession *)session data:(NSData *)data onTopic:(NSString *)topic qos:(MQTTQosLevel)qos retained:(BOOL)retained mid:(unsigned int)mid { // New message received in topic}
Publish a message to a topic:
[session publishData:someData onTopic:@"example/#" retain:NO qos:MQTTQosLevelAtMostOnce publishHandler:^(NSError *error) {}];
If you already have a self signed URL from broker like AWS IoT endpoint, use the url property of MQTTWebsocketTransport:
MQTTWebsocketTransport *transport = [[MQTTWebsocketTransport alloc] init];transport.url = @"wss://aws.iot-amazonaws.com/mqtt?expiry='2018-05-01T23:12:32.950Z'"MQTTSession *session = [[MQTTSession alloc] init];session.transport = transport;[session connectWithConnectHandler:^(NSError *error) { // Do some work}];
Installation
CocoaPods
Add this to your Podfile:
pod 'MQTTClient'
which is a short for:
pod 'MQTTClient/Min'pod 'MQTTClient/Manager'
The Manager subspec includes the MQTTSessionManager class.
If you want to use MQTT over Websockets:
pod 'MQTTClient/Websocket'
If you want to do your logging with CocoaLumberjack (recommended):
pod 'MQTTClient/MinL'pod 'MQTTClient/ManagerL'pod 'MQTTClient/WebsocketL'
Carthage
In your Cartfile:
github "novastone-media/MQTT-Client-Framework"
Manually
Git submodule
Add MQTT-Client-Framework as a git submodule into your top-level project directory or simply copy whole folderFind MQTTClient.xcodeproj and drag it into the file navigator of your app project.In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.Under "General" panel go to "Linked Frameworks and Libraries" and add MQTTClient.framework
Framework
Download MQTT-Client-FrameworkBuild it and you should find MQTTClient.framework under "Products" group.Right click on it and select "Show in Finder" option.Just drag and drop MQTTClient.framework to your project
Security Disclosure
If you believe you have identified a security vulnerability with MQTT-Client-Framework, please report it to ios@novastonemedia.com and do not post it to a public issue tracker.
Thanks
This project was originally written by Christoph Krey.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~