gpt4 book ai didi

ios - 适用于 iOS 的 Robbiehanson xmpp 框架不接收聊天消息

转载 作者:行者123 更新时间:2023-11-29 01:29:57 24 4
gpt4 key购买 nike

尝试使用 robbiehanson xmpp 创建一个非常简单的概念验证 iOS xmpp 应用程序 frame work ,只需要能够发送和接收消息和名册数据。我可以成功验证并发送消息,但是当用户尝试回复我的消息时,我没有收到它们。我已经实现了 didReceiveMessage 委托(delegate)方法,如下所示:

-(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message {
NSLog(@"incoming message: %@", message);
}

但我从未收到过此日志。如果我使用与此 xmpp 服务器通信的现有 Web 应用程序或 Android 应用程序登录,我会收到这些消息,因此我倾向于相信它们的格式正确。我需要向 XMPPStream 添加一个模块来接收消息吗?我正在像这样设置流(为了安全起见,一些字符串值已更改):

stream = [[XMPPStream alloc] init];
stream.enableBackgroundingOnSocket = YES;
stream.hostName = @"hostname.com";
stream.hostPort = 5222;

XMPPRosterCoreDataStorage* xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore];
XMPPRoster* xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
xmppRoster.autoFetchRoster = YES;
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
[stream addDelegate:self delegateQueue:dispatch_get_main_queue()];

XMPPJID* jid = [XMPPJID jidWithUser:@"username" domain:@"domain.com" resource:@"iOS"];

[stream setMyJID:jid];

[xmppRoster activate:stream];

[stream connectWithTimeout:XMPPStreamTimeoutNone error:&error]

然后在 xmppStreamDidConnect 方法中我执行此操作来进行身份验证

NSString *myPassword = @"password";
NSError *error = nil;

[stream authenticateWithPassword:myPassword error:&error]

当我发送消息时,我使用以下代码片段:

 MPPJID* recipient = [XMPPJID jidWithString:@"user@domain.com"];
XMPPMessage* message = [[XMPPMessage alloc] initWithType:@"chat" to:recipient];
[message addBody:@"hello world"];

[stream sendElement: message];

我想我缺少一些简单的东西,以前使用过它的人可以立即向我指出。如果需要解决此问题,我准备提供其他信息。

最佳答案

我只需要广播我的存在,然后我就可以接收消息了。

我将这些行添加到 streamDidAuthenticate 方法

XMPPPresence *presence = [XMPPPresence presence];
[sender sendElement:presence];

关于ios - 适用于 iOS 的 Robbiehanson xmpp 框架不接收聊天消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33552910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com