我正在使用 xmpp 在 IOS 中进行群聊。我可以成功创建组,但是在我邀请用户之后 didReceiveInvitation 方法不会在其他设备上调用。
下面是我的代码。
- (void) createGroupOnServer:(NSString *)groupName groupContacts:(NSMutableArray *)groupContacts
{
self.groupContacts = groupContacts;
XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
/**
* Remember to add 'conference' in your JID like this:
* e.g. uniqueRoomJID@conference.yourserverdomain
*/
XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.hiappserver", groupName]];
XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:self.xmppStream];
//[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:self.xmppStream.myJID.user
history:nil
password:nil];
[self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
NSLog(@"Room has been created successfully");
[self performSelector:@selector(ConfigureNewRoom:) withObject:sender afterDelay:2];
}
- (void)xmppRoomDidJoin:(XMPPRoom *)sender
{
}
-(void)ConfigureNewRoom:(XMPPRoom*)sender{
[sender fetchConfigurationForm];
[sender configureRoomUsingOptions:nil];}
- (void)xmppRoom:(XMPPRoom *)sender didConfigure:(XMPPIQ *)iqResult{
//[self showAlert:@"Room Created And Configured. Invite Users Now"];
//[self inviteUsers:sender];
for(int i = 0; i < self.groupContacts.count; i++)
{
NSString* contactNumber = [[self.groupContacts objectAtIndex:i] stringByReplacingOccurrencesOfString:@"+" withString:@""];
NSLog(@"Group Number = %@", contactNumber);
XMPPJID *inviteJid=[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@abcserver", contactNumber]];
[sender inviteUser:inviteJid withMessage:@"Join Chat Group."];
}
}
/**
* Necessary to prevent this message:
* "This room is locked from entry until configuration is confirmed."
*/
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm
{
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"]];
}
}
[sender configureRoomUsingOptions:newConfig];
[self.delegate groupDidCreateSuccessfully];
}
- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{
NSLog(@"Recieved Room Invitation from = %@ and Message = %@", roomJID, message);
}
我也在 .h 文件中提到了代表。任何帮助将不胜感激。
谢谢