无法将XMPPFramework连接到iOS中的Openfire服务器 [英] Unable to connect XMPPFramework to Openfire server in iOS
问题描述
我正在使用 iOS
聊天应用,用户登录应用。我已经从GitHub XMPPFramework 下载了 XMPPFramework
。我试图通过 XMPP 框架与 Openfire
服务器.com / tutorials / building-a-jabber-client-for-ios-xmpp-setup - mobile-7190rel =nofollow noreferrer>本教程。这是我将XMPP连接到openfire的代码。
I am working on an iOS
chat app where user login to app. I've downloaded XMPPFramework
from GitHub XMPPFramework. I am trying to connect XMPP
framework with Openfire
server by following this tutorial. Here is my code to connect XMPP to openfire.
- (BOOL)connect {
[self setupStream];
[xmppStream setHostName:@"192.168.1.5"];
[xmppStream setHostPort:5222];
NSString *jabberID = [[NSUserDefaults standardUserDefaults] stringForKey:@"userID"];
NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:@"userPassword"];
if (![xmppStream isDisconnected])
return YES;
if (jabberID == nil || myPassword == nil)
return NO;
[xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
password = myPassword;
NSError *error = nil;
if (![xmppStream isConnected])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
return NO;
}
return YES;
}
问题是当我运行应用程序时,它会显示警告无法连接到服务器
。我已经在StackOverflow上检查了很多问题,并尝试使用谷歌搜索,但找不到任何相关的解决方案。如何将它连接到Openfire服务?如果我在我的代码中做错了什么,请建议我用一段代码或教程来实现这一点。
The problem is when I run the app, it shows the alert can't connect to server
. I have checked many questions on StackOverflow and tried googling but couldn't find any relevant solution. How to connect it to the Openfire serve? If I am doing anything wrong in my code please suggest me with a snippet of code or a tutorial to make this happen.
推荐答案
希望这仍然相关,如果没有,希望它会帮助别人。
您的代码存在一些问题:
Hope this still relevant, if not, hopefully it will help others. There are some issues with your code:
-
我没有看到连接的调用,你应该添加这样的事情:
I don't see the call to connect, you should add something like this:
NSError *error = nil;
if (![_xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error connecting"
message:@"Msg"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}
大多数XMPP API都是异步的。
您必须设置流委托才能接收事件。
查看 XMPPStreamDelegate
和 XMPPStream#addDelegate
如果您不想自己查看代码 XMPPStream.h
,您可以实现 XMPPStreamDelegate
的所有方法并记录事件。这将有助于您了解框架的工作原理。
If you don't want to go through the code yourself XMPPStream.h
, you can implement all methods of XMPPStreamDelegate
and log the events. This will help you understand how the framework works.
希望这有帮助,Yaron
Hope this helps, Yaron
这篇关于无法将XMPPFramework连接到iOS中的Openfire服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!