如何使用XMPP框架发送消息

发布于 2024-10-05 05:28:57 字数 72 浏览 0 评论 0原文

我正在 iPhone 中使用 XMPP 框架创建一个聊天应用程序。我可以收到消息,但无法发送消息。任何人都可以给我解决这个问题吗?

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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你不是我要的菜∠ 2024-10-12 05:28:57
- (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];



    }
}

在你的 chatViewcontroller 中使用上面的代码..它对我来说工作得很好。

- (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.

多孤肩上扛 2024-10-12 05:28:57

试试这个:

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];

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];
美羊羊 2024-10-12 05:28:57

如果您正在使用 xmpp iPhone 示例应用程序...您可以使用类似以下内容,它应该可以帮助您入门:

NSString *msgText = @"test reply";

XMPPMessage* msg = [[XMPPMessage alloc] initWithType:@"chat" to:[XMPPJID jidWithString:displayName]];
[msg addBody:msgText];

[_xmppStream sendElement:msg];

只需将其放在

iPhoneXMPPAppDelegate.m 中的 xmppStream 委托方法中的警报下方:

-(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message

这会自动将“测试回复”发送回最初向您发送消息 glhf 的 jid

if you are using the xmpp iPhone example application... you can use something like the following and it should get you started:

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

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

glhf!

凉世弥音 2024-10-12 05:28:57

斯威夫特3答案:

let user = XMPPJID(string: "[email protected]")
let msg = XMPPMessage(type: "chat", to: user)
msg?.addBody("test message")
self.xmppStream.send(msg)

Swift 3 answer:

let user = XMPPJID(string: "[email protected]")
let msg = XMPPMessage(type: "chat", to: user)
msg?.addBody("test message")
self.xmppStream.send(msg)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文