XMPPRoom 网上可以找到很多讲解,这里是提醒下XMPPRoom中 leaveRoom 与destoryRoom 的作用,根据字面意思可以知道就是离开房间和删除群组的意思,但是前者具体作用是不再接受该群聊消息,源码如下
- (void)leaveRoom
{
dispatch_block_t block = ^{ @autoreleasepool {
XMPPLogTrace();
// <presence type='unavailable' to='darkcave@chat.shakespeare.lit/thirdwitch'/>
XMPPPresence *presence = [XMPPPresence presence];
[presence addAttributeWithName:@"to" stringValue:[myRoomJID full]];
[presence addAttributeWithName:@"type" stringValue:@"unavailable"];
[xmppStream sendElement:presence];
state &= ~kXMPPRoomStateJoining;
state &= ~kXMPPRoomStateJoined;
state |= kXMPPRoomStateLeaving;
}};
if (dispatch_get_specific(moduleQueueTag))
block();
else
dispatch_async(moduleQueue, block);
}
可以看到,状态设置为不可用(unavailable),不要理解错了.
其实可以用- (void)deactivate;方法,其源码如下:
- (void)deactivate
{
XMPPLogTrace();
dispatch_block_t block = ^{ @autoreleasepool {
if (self.isJoined)
{
[self leaveRoom];
}
[responseTracker removeAllIDs];
responseTracker = nil;
}};
if (dispatch_get_specific(moduleQueueTag))
block();
else
dispatch_sync(moduleQueue, block);
[super deactivate];
}