1010#import " MQTTKit.h"
1111#import " mosquitto.h"
1212
13- #if 0 // set to 1 to enable logs
13+ #if 1 // set to 1 to enable logs
1414
1515#define LogDebug (frmt, ...) NSLog (frmt, ##__VA_ARGS__);
1616
@@ -92,9 +92,9 @@ static void on_disconnect(struct mosquitto *mosq, void *obj, int rc)
9292{
9393 MQTTClient* client = (__bridge MQTTClient*)obj;
9494 LogDebug (@" [%@ ] on_disconnect rc = %d " , client.clientID , rc);
95- [client.publishHandlers removeAllObjects ];
96- [client.subscriptionHandlers removeAllObjects ];
97- [client.unsubscriptionHandlers removeAllObjects ];
95+ // [client.publishHandlers removeAllObjects];
96+ // [client.subscriptionHandlers removeAllObjects];
97+ // [client.unsubscriptionHandlers removeAllObjects];
9898
9999 client.connected = NO ;
100100 if (client.disconnectionHandler ) {
@@ -216,6 +216,14 @@ - (MQTTClient*) initWithClientId: (NSString *)clientId
216216 return self;
217217}
218218
219+ - (void ) destroy
220+ {
221+ if (mosq) {
222+ mosquitto_destroy (mosq);
223+ mosq = NULL ;
224+ }
225+ }
226+
219227- (void ) setMaxInflightMessages : (NSUInteger )maxInflightMessages
220228{
221229 mosquitto_max_inflight_messages_set (mosq, (unsigned int )maxInflightMessages);
@@ -226,11 +234,9 @@ - (void) setMessageRetry: (NSUInteger)seconds
226234 mosquitto_message_retry_set (mosq, (unsigned int )seconds);
227235}
228236
229- - (void ) dealloc {
230- if (mosq) {
231- mosquitto_destroy (mosq);
232- mosq = NULL ;
233- }
237+ - (void ) dealloc
238+ {
239+ [self destroy ];
234240}
235241
236242#pragma mark - Connection
@@ -255,7 +261,7 @@ - (void) connectWithCompletionHandler:(void (^)(MQTTConnectionReturnCode code))c
255261 }
256262 // add tls insecure set
257263 mosquitto_tls_insecure_set (mosq, self.tlsInsecure );
258- mosquitto_tls_opts_set (mosq,0 ," tlsv1" ,nil );
264+ mosquitto_tls_opts_set (mosq,1 ," tlsv1" ,nil );
259265
260266 mosquitto_connect (mosq, cstrHost, self.port , self.keepAlive );
261267
0 commit comments