Reputation: 133
I'm having difficulties to add friends, sending invitations and also in group chat like sending one message for all using xmpp. i know that I need to use XEP-0045. But I am not succeeded. Can anybody tell me how to do it.
if somebody has sample code that would be great..
Thanks in advance
Upvotes: 2
Views: 1324
Reputation: 350
Point 2: Send invitation to join chat room.
You can send invitation to others when you get the response in following delegate (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
}
Point 3: Send message to chat room's friends. Actually the message is broadcasted in group. Surely shall be delivered to all members in group.
- (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];
}
}
}
Upvotes: 2
Reputation: 776
for #3 : send message to chat room's friends.
-(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];
}
Upvotes: 2