0
votes

Hello I am making a chat app with XMPPFramework.

I have setup XMPPFramework in my project by referring this link:- http://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-xmpp-setup--mobile-7190

Code to send message:-

    NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
    [body setStringValue:messageStr];

    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:fnjid];
    [message addChild:body];
    [self.xmppStream sendElement:message];

This code was working good but now this is not working...method "send Element" is not calling..it is in xmppstream class.

- (void)sendElement:(NSXMLElement *)element

This method called when connection to server but not working only in send messages

1
Is self.xmppStream nil when sendElement: is not called?Larme

1 Answers

0
votes

Possibly, you have a problem with the compound and authorization ?

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    isXmppConnected = YES;
    NSError *error = nil;
    if (![[self xmppStream] authenticateWithPassword:password error:&error])
    {

    }
}

And

- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
    XMPPPresence *presence = [XMPPPresence presenceWithType:@"available"];
    [[self xmppStream] sendElement:presence];
}


In this case, the method does not work correctly , because state != STATE_XMPP_CONNECTED

- (void)sendElement:(NSXMLElement *)element
{
 if (element == nil) return;

 dispatch_block_t block = ^{ @autoreleasepool {

  if (state == STATE_XMPP_CONNECTED)
  {
   [self sendElement:element withTag:TAG_XMPP_WRITE_STREAM];
  }
  else
  {
   [self failToSendElement:element];
  }
 }};

 if (dispatch_get_specific(xmppQueueTag))
  block();
 else
  dispatch_async(xmppQueue, block);
}