当我发送邀请时,此功能被调用,但我无法理解代码行 应该用于接受邀请* 。我也试图创建一个多用户和多组邀请
叫做收到的留言功能。
- (void)xmppMUC:(XMPPMUC *) sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{
}
答案 0 :(得分:4)
这是您接受群组邀请的方式。您只需要激活您的XMPPMUC协议,如下所示:
XMPPMUC * xmppMUC = [[XMPPMUC alloc] initWithDispatchQueue:dispatch_get_main_queue()];
[xmppMUC activate:_xmppStream];
[xmppMUC addDelegate:self delegateQueue:dispatch_get_main_queue()];
接受MUC的传入邀请:
- (void)xmppMUC:(XMPPMUC *)sender didReceiveRoomInvitation:(XMPPMessage *)message
{
NSXMLElement * x = [message elementForName:@"x" xmlns:XMPPMUCUserNamespace];
NSXMLElement * invite = [x elementForName:@"invite"];
if (!isEmpty(invite))
{
NSString * conferenceRoomJID = [[message attributeForName:@"from"] stringValue];
[self joinMultiUserChatRoom:conferenceRoomJID];
}
}
- (void) joinMultiUserChatRoom:(NSString *) newRoomName
{
XMPPJID *roomJID = [XMPPJID jidWithString:newRoomName];
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
xmppRoom = [[XMPPRoom alloc]
initWithRoomStorage:roomMemoryStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:[self xmppStream]];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:@"YOUR NICKNAME" history:nil];
}
答案 1 :(得分:2)
接受来电邀请:
- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{ XMPPRoom *mu = [[XMPPRoom alloc] initWithRoomStorage:xmpproomMstorage jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[mu activate:xmppStream];
[mu addDelegate:self delegateQueue:dispatch_get_main_queue()];
self.toSomeOne = roomJID;
[mu activate: self.xmppStream];
[mu fetchConfigurationForm];
[mu addDelegate:self delegateQueue:dispatch_get_main_queue()];
[mu joinRoomUsingNickname:xmppStream.YourJid.user history:nil password:@"Your Password"];
self.toSomeOne = roomJID;
XMPPPresence *presence = [XMPPPresence presence];
[[self xmppStream] sendElement:presence];
[xmppRoster addUser:roomJID withNickname:roomJID.full];
[self goOnline];
}
答案 2 :(得分:0)
在我的情况下,我需要使用两个答案并定义自己像
@interface XMPPDelegate : NSObject <XMPPMUCDelegate>
激活XMPPMUC协议如下:
XMPPMUC * xmppMUC = [[XMPPMUC alloc]
initWithDispatchQueue:dispatch_get_main_queue()];
[xmppMUC activate:_xmppStream];
[xmppMUC addDelegate:self delegateQueue:dispatch_get_main_queue()];
收到加入消息:
- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{
DDLogDebug(@"%@", message);
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname: xmppStream.myJID.user history:nil password:password];
XMPPPresence *presence = [XMPPPresence presence];
[[self xmppStream] sendElement:presence];
[xmppRoster addUser:roomJID withNickname:roomJID.full];
[self goOnline];
}