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 ファイルで言及しました。どんな助けでも大歓迎です。
ありがとう