Pubnub订阅1对1聊天
问题描述:
在pubnub群聊很容易,但我找不到正确的方式进行1对1聊天,我跟着http://pubnub.github.io/pubnub-design-patterns/2015/03/05/Inbound-Channel-Pattern.html。 因此,对于每个用户订阅唯一频道的结论,不是吗?Pubnub订阅1对1聊天
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@“mypublishkey” subscribeKey:@“mysubskey”];
[email protected]“myuuid”;//unique id help to find presence
configuration.presenceHeartbeatValue = 120;
//unsubscribe from channel until no response in 120 sec
configuration.presenceHeartbeatInterval = 30;//send to server each 30 second
self.client = [PubNub clientWithConfiguration:configuration];
[self.client addListener:self];
_delegateconfig=delegate;
// Subscribe to demo channel with presence observation
[self.client subscribeToChannels: @[channelname] withPresence:YES];
/- 用于列出所有用户或信道---/
我称为hereNowWithCompletion 这表明是确定所有信道列表
例如https://www.pubnub.com/docs/cocoa-objective-c/presence
/--------取消订阅频道--------/
[self.client unsubscribeFromChannels:@ [channelname] withPresence:YES]; 不起作用,因为当我打电话给这里时,NowWithCompletion显示的是之前的所有列表,但在120秒后没什么问题,但我想要立即重新生成。
答
是,私人聊天仅仅是一个只有两个用户订阅的频道和发布消息,该通道的通道。这里现在只是查找谁正在主动订阅频道的一种手段。查看[聊天基础知识](https://www.pubnub.com/docs/web-javascript/chat-fundamentals)了解有关聊天最佳做法的更多详情。 –
@ craig-conover,谢谢你的回复,我仍然对此有疑惑,假设2个用户想按照你的建议聊天,比如“channel_a-b”,但是如果A发送消息给用户B,那么用户B (void)客户端:(PubNub *)客户端didReceiveMessage:(PNMessageResult *)将不能从该频道接收消息,除非用户B订阅相同频道,否则此委托方法将不会呼叫用户b直到他订阅相同频道 - )消息 – saurabh
你是对的。因此,您需要邀请B加入该频道,并等待B接受邀请(订阅频道)。但是,这甚至不是必要的,因为当B第一次订阅频道时,B可以调用历史记录(存储必须启用)。 –