Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send message using XMPP Framework

I am creating a chat application using XMPP Framework in iphone. i could get received messages but i am not able to send a message. can any one give me solution for this??

like image 558
Prashant Bhayani Avatar asked Dec 01 '10 13:12

Prashant Bhayani


2 Answers

- (void)sendMessage:(NSString *)msgContent
{

    NSString *messageStr = textField.text;

    if([messageStr length] > 0)
    {
        NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
        [body setStringValue:messageStr];

        NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
        [message addAttributeWithName:@"type" stringValue:@"chat"];
        [message addAttributeWithName:@"to" stringValue:[jid full]];
        [message addChild:body];

        [xmppStream sendElement:message];



    }
}

use the above code in you chatViewcontroller ..it is working fine for me.

like image 99
Raj Avatar answered Oct 09 '22 02:10

Raj


Try this :

XMPPUserCoreDataStorage *user = [[self fetchedResultsController] objectAtIndexPath:indexPath];

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

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[user.jid full]];
[message addChild:body];

[[self xmppStream] sendElement:message];
like image 31
Prashant Bhayani Avatar answered Oct 09 '22 02:10

Prashant Bhayani