使用xmpp我可以创建群组并向朋友发送邀请但是当我在群组上发送消息时,会员将永远不会收到该消息。
会员必须接受邀请吗?如果是,请告诉我怎么做?
请参考下面的代码,如果我犯了任何错误,或者我仍然缺少任何东西,那么请指导我,以便我可以在群组中发送和接收消息并与朋友聊天。
下面我将我的一些代码片段附加到xmpp中的create group并发送消息。
[self setUpRoom:[NSString stringWithFormat:@"%@@conference.myserver",@"GroupName"]];
-(void)setUpRoom:(NSString *)ChatRoomJID {
// Configure xmppRoom
XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:ChatRoomJID];
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:_ro(@"LoginNumber")
history:nil
password:nil];
[self performSelector:@selector(ConfigureNewRoom:) withObject:nil afterDelay:4];
}
现在我已经使用这个片段了解房间确认
- (void)ConfigureNewRoom:(id)sender
{
[xmppRoom configureRoomUsingOptions:nil];
[xmppRoom fetchConfigurationForm];
[xmppRoom fetchBanList];
[xmppRoom fetchMembersList];
[xmppRoom fetchModeratorsList];
}
XMPPRoom委派方法
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);
// I am inviting friends after room is created
for (int i = 0; i<[self.friendListArray count]; i++)
{
NSString * tempStr=[NSString stringWithFormat:@"%@@myserver",[[self.friendListArray objectAtIndex:i] valueForKey:@"UserNumber"]];
[sender inviteUser:[XMPPJID jidWithString:tempStr] withMessage:@"Greetings!"];
}
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);
NSLog(@"........Room Did join.......");
}
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm
{
DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);
NSXMLElement *newConfig = [configForm copy];
NSArray *fields = [newConfig elementsForName:@"field"];
for (NSXMLElement *field in fields)
{
NSString *var = [field attributeStringValueForName:@"var"];
// Make Room Persistent
if ([var isEqualToString:@"muc#roomconfig_persistentroom"])
{
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
}
if ([var isEqualToString:@"roomconfig_enablelogging"])
{
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
}
if ([var isEqualToString:@"muc#roomconfig_maxusers"])
{
[field removeChildAtIndex:0];
[field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"100"]];
}
}
[sender configureRoomUsingOptions:newConfig];
}
点击按钮时在组中发送消息以进行测试
-(void)sendGroupMessage
{
[xmppRoom sendMessageWithBody:@"Hi All"];
NSXMLElement *x = [NSXMLElement elementWithName:@"groupchat" xmlns:XMPPMUCNamespace];
XMPPMessage *message = [XMPPMessage message];
[message addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@/%@",[xmppRoom.roomJID full],_ro(@"LoginNumber")]];
[message addChild:x];
NSLog(@"x in Invite === %@",x);
[xmppStream sendElement:message];
}
答案 0 :(得分:2)
而不是:
[xmppStream sendElement:message]
尝试:
[xmppRoom sendMessage:message]
答案 1 :(得分:0)
对于MUC聊天,会员必须接受邀请。 你可以在这里找到答案: