我正在设置 ejabberd,我成功地配置了服务器,但是在客户端我们需要 XMPP 框架,
我用谷歌搜索了以下链接
http://deusty.blogspot.in/2008/08/xmppframework-on-iphone.html
http://iphone4developer.blogspot.in/2011/07/how-to-add-xmpp-in-your-ios-project.html
我下载了 robbiehanson/XMPPFramework 但它抛出错误,一些链接给我 404 错误(它们已删除)
我从这个链接(https://github.com/funkyboy/Building-a-Jabber-client-for-iOS)下载了 jabber 客户端,但是 xmpp 框架文件从应用程序中抛出错误(那些已经被删除)
我得到了一个 iPhoneXMPP 样本,但它抛出错误“无法连接到服务器。检查 xmppStream.hostName”我在 willSecureWithSettings 方法中给出了我的主机名
疑问:
1)请指导我正确下载正确的XMPP框架
2)如何配置ejabber客户端?
请指导我
提前致谢
最佳答案
我大约 6 个月前从这个链接下载了 robbiehanson/XMPPFramework:https://github.com/robbiehanson/XMPPFramework .我按照 Getting Started 中提到的步骤进行操作部分。它没有抛出任何错误。只需尝试按照这些步骤为您的应用程序设置 xmppframework。
在示例应用程序中,我找到了我在启动应用程序时调用的函数 setupStream()
。在此函数中,我创建了一个 xmppStream 并激活了我的应用程序所需的不同模块。例如
xmppStream = [[XMPPStream alloc] init];
// Activate xmpp modules after creating them
[xmppReconnect activate:xmppStream];
[xmppRoster activate:xmppStream];
[xmppvCardTempModule activate:xmppStream];
[xmppvCardAvatarModule activate:xmppStream];
[xmppCapabilities activate:xmppStream];
// Add ourself as a delegate to anything we may be interested in
[xmppStream addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
[xmppStream setHostName:XMPPHOST];
[xmppStream setHostPort:5222];
// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
设置流后,你需要像这样进行认证:
- (BOOL)connect:(NSString *)myJID //username registered with server
{
if (![xmppStream isDisconnected]) {
return YES;
}
if (myJID == nil) {
return NO;
}
[xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
NSError *error = nil;
if (![xmppStream connect:&error])
{
if(DEBUG)
{
NSLog(@"ERROR: Not connected to XMPP Server");
}
DDLogError(@"Error connecting: %@", error);
return NO;
}
return YES;
}
此函数将由框架调用并在此处传递密码:
- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
if(sender == xmppStream)
{
//DDLogVerbose(@"In xmppStream: %@: %@", THIS_FILE, THIS_METHOD);
isXmppConnected = YES;
NSError *error = nil;
if (![[self xmppStream] authenticateWithPassword:password error:&error])
{
DDLogError(@"Error authenticating: %@", error);
}
}
}
现在如果用户通过身份验证,将调用此函数:
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
if(sender == xmppStream)
{
[self goOnline];
}
}
goOnline 会将用户的状态发送到服务器:
- (void)goOnline
{
XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit
[xmppStream sendElement:presence];
}
现在您可以发送/接收消息/状态等
关于iphone - 需要XMPP框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15131659/