1

取消订阅频道在 socketcluster 上不起作用。

我必须订阅 20 个频道。现在我想取消订阅 10 个频道。所以我们使用下面的代码进行订阅。

//  For subscribe 
SoketManager.client.subscribeAck(channelName:"random") { (str, obj1, obj2) in
        print ("Got data for channel", str)
 }

//  Listening to channel                 
SoketManager.client.onChannel(channelName:"random", ack: {
         (channelName : String , data : AnyObject?) in
      print ("Got data for channel", channelName, " object data is ", data ?? "")
 })

我们使用以下代码取消订阅。

//  For unsubscribe 
 SoketManager.client.unsubscribeAck(channelName:"random", ack : {
       (channelName : String, error : AnyObject?, data : AnyObject?) in
          if (error is NSNull) {
                        print("Successfully unsubscribed to channel ", channelName)
           } else {
                        print("Got error while unsubscribing ", error ?? "")
          }
 })

当我调用“unsubscribeAck”方法时总是会出错。这是错误。

{
    message = "Failed to unsubscribe socket from the [object Object] channel - Socket YFaGYE5Tbu1_8we2AAAG tried to unsubscribe from an invalid channel name";
    name = BrokerError;
}

我也在尝试使用 socketcluster 演示,但它对我不起作用。

Github 链接:https ://github.com/sacOO7/socketcluster-client-swift

感谢你的帮助。

谢谢

4

0 回答 0