novastone-media / MQTT-Client-Framework

iOS, macOS, tvOS native ObjectiveC MQTT Client Framework
Other
1.84k stars 466 forks source link

I wrote it according to your usage, but there is no return value, subscribe to the topic that what is going on #163

Closed shanyulaile closed 7 years ago

shanyulaile commented 8 years ago

I wrote it according to your usage, but there is no return value, subscribe to the topic that what is going on. The following code `- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {

MQTTCFSocketTransport *transport = [[MQTTCFSocketTransport alloc] init];
transport.host = @"192.168.12.46";
transport.port = 1883;
MQTTSession *session = [[MQTTSession alloc] init];
session.userName = @"admin";
session.password = @"admin";
NSString *clientID = [[[UIDevice currentDevice]identifierForVendor]UUIDString];
session.clientId = clientID;
session.transport = transport;
session.delegate = self;
[session connectAndWaitTimeout:300];
[session subscribeToTopic:kTopic atLevel:2 subscribeHandler:^(NSError *error, NSArray<NSNumber *> *gQoss){
    if (error) {
        NSLog(@"Subscription failed %@", error.localizedDescription);
    } else {
        NSLog(@"Subscription sucessfull! Granted Qos: %@", gQoss);
    }
}];
return YES;

} This part which has not been executed if (error) { NSLog(@"Subscription failed %@", error.localizedDescription); } else { NSLog(@"Subscription sucessfull! Granted Qos: %@", gQoss); } ` thanks

ckrey commented 8 years ago

Did your app actually connect successfully? Check session.status after

[session connectAndWaitTimeout:300];

You may switch on debug level by changing in MQTTLog.h:

            static const DDLogLevel ddLogLevel = DDLogLevelWarning;

to

            static const DDLogLevel ddLogLevel = DDLogLevelVerbose;