gpt4 book ai didi

iOS 与 XMPP 的连接失败

转载 作者:行者123 更新时间:2023-11-28 18:30:30 26 4
gpt4 key购买 nike

我正在使用 xmpp 服务器在 iOS 中开发一个聊天应用程序。当我尝试连接到服务器时,它毫无异常(exception)地返回 0。据我所知,所有服务器凭据都是真实的。我尝试了很多次,但找不到任何富有成效的帮助。请给我一个方向,我该怎么做。这是下面的代码。

xmppStream = [[XMPPStream alloc] init];

// [self setupStream];
NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
[xmppStream sendElement:presence];

[xmppStream setMyJID:[XMPPJID jidWithString:@"app.com"]];

[xmppStream setHostName:@"appname.com"];
[xmppStream setHostPort:5222];

NSError *error2;
if ([xmppStream connect:&error2])
{
NSLog(@"Connected to XMPP.");
}
else
{
NSLog(@"Error connecting to XMPP: %@",[error2 localizedDescription]);
}
[self xmppStreamDidConnect:xmppStream];

//method is
- (void)setupStream {
NSLog(@"setupStream in delegate");
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
self.xmppStream.hostName = @"appname.com";
self.xmppStream.hostPort = (port);
[self connect];
}

最佳答案

遵循 this link 中给出的连接类

仅当您指定错误的 HostNameHostPortJID 时,与服务器的连接才会返回“0”。

还有一件事你不需要显式调用 xmppStreamDidConnect 它将作为来自 XMPPFramework 的委托(delegate)被调用。

关于iOS 与 XMPP 的连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32451543/

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