didReceiveInvitation does not work ios xmpp after sending invitation to users

716 views Asked by At

I am working on group chat in IOS using xmpp. I can create the group successfully but after i invite the users didReceiveInvitation method does not call on other device.

Below is my code.

- (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. [email protected]
     */

    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);
    }

I have mentioned the delegates proper in .h file as well. any help will be appreciated.

Thanks

0

There are 0 answers