novastone-media / MQTT-Client-Framework

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

how to subscribe many topic? #127

Closed roverk8y closed 7 years ago

roverk8y commented 8 years ago

i run you demo code(https://github.com/ckrey/MQTTChat) it work well i have about 4~6 topic need to subscribe,and we don't use "#" because the topic have 20 so what should i do ? for statment the fllowing code?

 if (!self.manager) {
        self.manager = [[MQTTSessionManager alloc] init];
        self.manager.delegate = self;
        self.manager.subscriptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:MQTTQosLevelExactlyOnce]
                                                                 forKey:[NSString stringWithFormat:@"%@/#", self.base]];
        [self.manager connectTo:self.mqttSettings[@"host"]
                           port:[self.mqttSettings[@"port"] intValue]
                            tls:[self.mqttSettings[@"tls"] boolValue]
                      keepalive:60
                          clean:true
                           auth:false
                           user:nil
                           pass:nil
                      willTopic:[NSString stringWithFormat:@"%@/%@-%@",
                                 self.base,
                                 [UIDevice currentDevice].name,
                                 self.tabBarItem.title]
                           will:[@"offline" dataUsingEncoding:NSUTF8StringEncoding]
                        willQos:MQTTQosLevelExactlyOnce
                 willRetainFlag:FALSE
                   withClientId:nil];
    } else {
        [self.manager connectToLast];
    }
ckrey commented 8 years ago
NSDictionary *subscriptions = @{
    @"topic1": @MQTTQosLevelExactlyOnce,
    @"topic2": @MQTTQosLevelExactlyOnce
};

or

NSMutableDictionary *subscriptions = [[NSMutableDictionary alloc] init];
[subscriptions setObject:@MQTTQosLevelExactlyOnce forKey:"topic1"];
[subscriptions setObject:@MQTTQosLevelExactlyOnce forKey:"topic2"];
[subscriptions setObject:@MQTTQosLevelExactlyOnce
   forKey:"[NSString stringWithFormat:@"%@/#", self.base]];

and then

 self.manager.subscriptions = subscriptions;
roverk8y commented 8 years ago

thank you very much ! it work well but i have new question that is how to disable DDLog in version 1.4.2 ?