如果我用单个pubnub实例多次订阅了一个频道,它是否会订阅,如果它订阅了哪个回调将被执行?
答案 0 :(得分:7)
成功订阅频道后,系统会调用connectCallback
。
在此之后,每当您致电subscribe
到其他渠道时,系统都会调用connectCallback
。
但如果您订阅了您已订阅的频道,则connectCallback
将不会被调用(基本上是无操作)。
Sample Java/Android subscribe
code:
pubnub.subscribe("my_channel", new Callback() {
@Override
public void connectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : CONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
@Override
public void disconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
public void reconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
@Override
public void successCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : " + channel + " : "
+ message.getClass() + " : " + message.toString());
}
@Override
public void errorCallback(String channel, PubnubError error) {
System.out.println("SUBSCRIBE : ERROR on channel " + channel
+ " : " + error.toString());
}
}
);