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??
我在iphone中使用XMPP Framework创建了一个聊天应用程序。我可以收到消息,但我无法发送消息。谁能给我解决这个问题?
4 个解决方案
#1
11
- (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.
你在chatViewcontroller中使用上面的代码..对我来说工作正常。
#2
3
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];
#3
2
if you are using the xmpp iPhone example application... you can use something like the following and it should get you started:
如果您使用的是xmpp iPhone示例应用程序...您可以使用以下内容,它应该让您入门:
NSString *msgText = @"test reply";
XMPPMessage* msg = [[XMPPMessage alloc] initWithType:@"chat" to:[XMPPJID jidWithString:displayName]];
[msg addBody:msgText];
[_xmppStream sendElement:msg];
just place this right below the alert they have in there in the xmppStream delegate method in
只需将它放在它们在xmppStream委托方法中的警报下方
iPhoneXMPPAppDelegate.m:
-(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
This will automatically send "test reply" back to the jid that initially sent you the message
这将自动将“测试回复”发送回最初向您发送消息的jid
glhf!
#4
0
Swift 3 answer:
斯威夫特3回答:
let user = XMPPJID(string: "user@example.com")
let msg = XMPPMessage(type: "chat", to: user)
msg?.addBody("test message")
self.xmppStream.send(msg)
#1
11
- (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.
你在chatViewcontroller中使用上面的代码..对我来说工作正常。
#2
3
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];
#3
2
if you are using the xmpp iPhone example application... you can use something like the following and it should get you started:
如果您使用的是xmpp iPhone示例应用程序...您可以使用以下内容,它应该让您入门:
NSString *msgText = @"test reply";
XMPPMessage* msg = [[XMPPMessage alloc] initWithType:@"chat" to:[XMPPJID jidWithString:displayName]];
[msg addBody:msgText];
[_xmppStream sendElement:msg];
just place this right below the alert they have in there in the xmppStream delegate method in
只需将它放在它们在xmppStream委托方法中的警报下方
iPhoneXMPPAppDelegate.m:
-(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
This will automatically send "test reply" back to the jid that initially sent you the message
这将自动将“测试回复”发送回最初向您发送消息的jid
glhf!
#4
0
Swift 3 answer:
斯威夫特3回答:
let user = XMPPJID(string: "user@example.com")
let msg = XMPPMessage(type: "chat", to: user)
msg?.addBody("test message")
self.xmppStream.send(msg)