我很难添加朋友,发送邀请以及在群聊中,比如使用xmpp为所有人发送一条消息。我知道我需要使用XEP-0045。但我没有成功。谁能告诉我怎么做。
如果某人的示例代码很棒......
提前致谢
答案 0 :(得分:2)
#3:向聊天室的朋友发送消息。
-(void) sendGroupMessage:(NSString *) groupJID Message:(NSString *)msg{
XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",groupJID,SERVER_URL]];
XMPPRoom *muc = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[muc activate:xmppStream];
[muc addDelegate:self delegateQueue:dispatch_get_main_queue()];
[muc sendMessageWithBody:msg];
}
答案 1 :(得分:2)
第2点:发送加入聊天室的邀请。
当您在以下委托中获得回复时,您可以向其他人发送邀请(xmppRoomDidCreate):
- (void)xmppRoomDidCreate:(XMPPRoom *)xmppRoom
{
NSLog(@"xmppRoomDidCreate");
[xmppRoom inviteUser:[User JID Here] withMessage:@"Your Message Here"];
// You can send invitations in loop if you have multiple users to invite
}
第3点:向聊天室的朋友发送消息。 实际上,该消息是在组中广播的。肯定会交付给所有小组成员。
- (void) sendMessageInGroup:(NSString *) message withGroupName:(NSString *) groupName
{
NSString * qualifiedGroupName = [NSString stringWithFormat:@"%@@%@", [groupName lowercaseString], SERVER_NAME];
// self.xmppRoomDetails consists of your muc rooms' objects i.i XMPPRoom
for (int i = 0; i < self.xmppRoomDetails.count; i++)
{
XMPPRoom * room = [self.xmppRoomDetails objectAtIndex:i];
XMPPJID * myRoomJID = room.myRoomJID;
NSString * roomName = [NSString stringWithFormat:@"%@@%@", [myRoomJID.user lowercaseString], SERVER_NAME];
if ([qualifiedGroupName rangeOfString:roomName].location != NSNotFound)
{
XMPPRoom * sendMessageWithRoom = [self.xmppRoomDetails objectAtIndex:i];
[sendMessageWithRoom sendMessage:message];
}
}
}