[英]iOS Connection With XMPP Failed
I am developing a chat app in iOS using xmpp server. 我正在使用xmpp服务器在iOS中开发聊天应用程序。 When i tried to connect to the server it returned 0 without any exception. 当我尝试连接到服务器时,它毫无例外地返回0。 All server credentials are true to the best of my knowledge. 据我所知,所有服务器凭据都是真实的。 I tried many a times but couldn't found any fruitful help. 我尝试了很多次,但没有找到任何富有成效的帮助。 Kindly give me a direction what should I do. 请给我一个方向,我应该怎么做。 Here is a code below. 这是下面的代码。
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];
}
Follow the connection class given in this link 遵循此链接中给出的连接类
Connection to server returns “0” only when you specify wrong HostName
, HostPort
or JID
. 仅当您指定错误的HostName
, HostPort
或JID
时,与服务器的连接才会返回“ 0”。
And one more thing you need not call xmppStreamDidConnect
explicitly it will be called as delegate from XMPPFramework
. 还有一件事,您无需显式调用xmppStreamDidConnect
,它将作为XMPPFramework
委托来XMPPFramework
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.