物联网平台iOS开源MQTT协议接入代码测试

1.首先在pod文件中,添加mqttclient包

platform :ios, '9.0'
target 'MQTT-ClientText' do
    pod 'MQTTClient'
end

2.控制器代码如下

#import "MQTTClient.h"

@interface ViewController ()<MQTTSessionDelegate>
@property (nonatomic,strong)MQTTSessionManager *manager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.manager = [[MQTTSessionManager alloc]init];
    self.manager.delegate = self;
    NSString *realmName = @"productkey.iot-as-mqtt.cn-shanghai.aliyuncs.com";
    NSString *userName = @"test&xxxx";
    NSString *password = @"xxxxxxxx";
//
    [self.manager connectTo:realmName port:1883
                        tls:NO
                  keepalive:60
                      clean:NO auth:NO
                       user:userName
                       pass:password
                       will:nil
                  willTopic:nil willMsg:nil
                    willQos:0
             willRetainFlag:YES
               withClientId:@"xxxx"
             securityPolicy:nil
               certificates:nil
              protocolLevel:0
             connectHandler:nil];    
}

ps:此处的password需要手动签名,签名代码之后研究一下,暂时没找到可以使用的签名代码直接接入

上一篇:QTP整合QC自动化测试--目录结构搭建


下一篇:接入支付宝解决规模增长难题,人人租机订单量增长15倍 | C位小程序访谈