先放结论:
修改类XMPPStream.m中,注掉该类中1951-1955行代码,如下
if ([self supportsSCRAMSHA1Authentication])
{
someAuth = [[XMPPSCRAMSHA1Authentication alloc] initWithStream:self password:password];
result = [self authenticate:someAuth error:&err];
}
// else if ([self supportsDigestMD5Authentication])
// {
// someAuth = [[XMPPDigestMD5Authentication alloc] initWithStream:self password:password];
// result = [self authenticate:someAuth error:&err];
// }
else if ([self supportsPlainAuthentication])
{
someAuth = [[XMPPPlainAuthentication alloc] initWithStream:self password:password];
result = [self authenticate:someAuth error:&err];
}
else if ([self supportsDeprecatedDigestAuthentication])
{
someAuth = [[XMPPDeprecatedDigestAuthentication alloc] initWithStream:self password:password];
result = [self authenticate:someAuth error:&err];
}
else if ([self supportsDeprecatedPlainAuthentication])
{
someAuth = [[XMPPDeprecatedDigestAuthentication alloc] initWithStream:self password:password];
result = [self authenticate:someAuth error:&err];
}
else
{
NSString *errMsg = @"No suitable authentication method found";
NSDictionary *info = @{NSLocalizedDescriptionKey : errMsg};
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamUnsupportedAction userInfo:info];
result = NO;
}
PS:上文中注掉的那几行就是。
源自于:http://www.cocoachina.com/bbs/read.php?tid-245199-page-2.html
然后就能解决了,以下是本人废话:
在最初接触XMPP时,OpenFire+MySQL本地服务器。在进行学习时经常遇到的一个问题是注册正常,但是登录的时候会出现问题。一只返回密码错误,如下:
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
这个问题最麻烦的是一下几点:
第一,密码绝对没有问题,刚刚注册的也提示有问题;
第二,XMPP的框架中,通知该错误是走的XMPP Stream Delegate的协议方法,返回的error是空,也没有errorCode之类的提示信息。
第三,网上的资料大都说的很详细,但是读完了你会发现并不知道该怎么办。例如这篇:http://www.tuicool.com/articles/Jza6nuu
这种文章最后都会说,XMPP认证的问题,一般都是与JID有关的,因此解决这类问题,首选的入口就是分析一下XMPPStream的JID,客户端在与服务器连接后,Socket就绑定了这个端口,用来处理与服务器的往返数据,认证就是其中之一.而且,往往我们在与服务器来连接的时候,为了简便,经常使用localhost或者127.0.0.1来当做域名的部分,这时候要尤其注意,因为使用Spark或者其他客户端程序登录的时候,使用这样的域名登录服务器是没有问题的,但在代码中处理就要特别小心,一定要在服务器的后段,确认域名统一:
否则,就会出现本文提示到的这个常见错误!!!!!!
然而作为新手的我们只能是一脸懵逼的点开,一脸懵逼的关掉。