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??
- (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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With