我正在使用 XMPPFramework 编写一个 iOS 客户端。我无法重新注册用户。我已经配置了 ejabberd 服务器,它已经启动并正在运行。我对此没有任何问题。我可以从 Ejabberd 的门户网站注册用户。但是当我尝试从 iOS 客户端注册用户时出现问题。服务器日志如下
=INFO REPORT==== 2014-04-26 12:06:43 ===
I(<0.380.0>:ejabberd_listener:281) : (#Port<0.3865>) Accepted connection {{211,28,44,250},49742} -> {{172,31,0,235},5222}
=INFO REPORT==== 2014-04-26 12:06:44 ===
I(<0.424.0>:ejabberd_c2s:802) : ({socket_state,gen_tcp,#Port<0.3865>,<0.423.0>}) Failed authentication for xcc@localhost
授权方式是odbc。由于我使用 mysql 进行数据和消息存储。
我从客户端抓取的日志如下
2014-04-25 20:46:49:384 iPhoneXMPP[1971:90b] SEND: <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5"/>
2014-04-25 20:46:49:620 iPhoneXMPP[1971:650b] RECV: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">bm9uY2U9IjMzNzkzODUwOTEiLHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bWQ1LXNlc3M=</challenge>
2014-04-25 20:46:49:621 iPhoneXMPP[1971:650b] SEND: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9ImlvYzEiLHJlYWxtPSJsb2NhbGhvc3QiLG5vbmNlPSIzMzc5Mzg1MDkxIixjbm9uY2U9IkMzN0U0NjlBLTg0RUUtNEY3RS1CNTEzLTM5RUJFREU0NzQ3NCIsbmM9MDAwMDAwMDEscW9wPWF1dGgsZGlnZXN0LXVyaT0ieG1wcC9sb2NhbGhvc3QiLHJlc3BvbnNlPTQzYTY5OTVlZmY2Y2UwNzA0YmJkNWM4OWZiNGU5ZDQ1LGNoYXJzZXQ9dXRmLTg=</response>
2014-04-25 20:46:49:865 iPhoneXMPP[1971:4953] RECV: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
2014-04-25 20:46:49:865 iPhoneXMPP[1971:90b] iPhoneXMPPAppDelegate: xmppStream:didNotAuthenticate:
2014-04-25 20:46:49.865 iPhoneXMPP[1971:90b] num--680
2014-04-25 20:46:49.866 iPhoneXMPP[1971:90b] elements--(
"<username>ioc1@localhost</username>",
"<password>ioc</password>",
"<name>ioc1@localhost</name>",
"<accounttype>1</accounttype>",
"<devicetoken>680</devicetoken>",
"<email>ioc1@localhost</email>"
)
重要的是不要在下面
2014-04-25 20:46:49:865 iPhoneXMPP[1971:4953] 接收:
我正在使用 registerwithpassword 方法,我真的很困惑为什么我无法注册。我相信 auth_method 只有在尝试登录时才会发挥作用,因为它需要一些身份验证机制才能登录。但在这里我只是注册。为什么我无法注册。我相信这不是主机名的问题,因为我收到一条日志行“@localhost 的身份验证失败”
这意味着我正在访问服务器。我在阻止我的 ejabberd.cfg 文件中缺少什么。
请注意:此外,我尝试将 authmethod 作为内部方法(虽然在帮助中提到它与 mnesia 有关 - 内置数据库,我正在使用 mysql)但仍然遇到同样的问题,我相信客户端无法由于某些连接设置而注册用户。
问题出在客户端还是服务器端。请指导我。感谢您的宝贵时间。
最佳答案
为了注册有效,您需要确保流已连接。我在下面展示了如何注册用户的示例。
- (IBAction)signUpButtonPressed:(UIButton *)sender {
// when the sign up button is pressed, set the JID for the xmpp stream
[self.xmppStream setMyJID:[XMPPJID jidWithString:jid]];
// check that the stream is not disconnected
if([self.xmppStream isDisconnected]){
// stream is not connected, attempt to connect
if (![self.xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
NSlog(@"Error connecting: %@", error);
}
// after stream connects, call [self beginRegistration] in xmppStreamDidConnect delegate method
} else {
[self beginRegistration];
}
}
-(void) beginRegistration {
// check if inband registration is supported
if (self.xmppStream.supportsInBandRegistration) {
if (![self.xmppStream registerWithPassword:password error:&error]) {
NSlog(@"Registration error: %@", error);
}
} else {
NSlog(@"Inband registration is not supported");
}
}
要检查注册是否成功,请使用 xmppStreamDidRegister:(XMPPStream *)sender
和 xmppStream:(XMPPStream *)sender didNotRegister:(NSXMLElement *)error
委托(delegate)方法。
如果这有帮助,请告诉我。
关于mysql - 无法使用 XMPPFramework 在 Ejabberd 中注册用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23310823/