折腾:
期间,代码:
func xmppStream(sender: XMPPStream!, didNotAuthenticate error: DDXMLElement!) { print("didNotAuthenticate") print("error=\(error)") //error=<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure> }
遇到错误:
<failure xmlns=”urn:ietf:params:xml:ns:xmpp-sasl”><not-authorized/></failure>
搜:
<failure xmlns=”urn:ietf:params:xml:ns:xmpp-sasl”><not-authorized/></failure>
参考:
去openfire服务器看看:

服务器属性
服务器启动时间: 1 天, 6 小时, 9 分钟 — started 2015-11-24 0:29:14
版本: Openfire 3.10.3
Openfire 主目录: /opt/openfire
服务器名称: localhost
所以是:
服务器中是localhost
去改为:

然后再去代码中试试:
错误依旧。
抽空继续:
看看此错误相关的openfire的IP地址或者localhost方面的事情,估计是都设置了IP就可以了?
另外也去看看:是不是服务器密码是某种加密方式的,而此处是明文发送的,所以失败了?
看到官网的解释了:
If JID mapping is unsuccessful, then the server SHOULD return a SASL failure condition of <not-authorized/> and close the stream.
Example 16.
<failure xmlns=’urn:ietf:params:xml:ns:xmpp-sasl’>
<not-authorized/>
</failure>
</stream:stream>
所以:
此处是JID不匹配而导致此错误的。
然后去openfire后台确认当前是:
属性名 属性值 编辑 加密 删除
admin.authorizedJIDs
属性名 | 属性值 | 编辑 | 加密 | 删除 |
---|---|---|---|---|
admin.authorizedJIDs | ||||
adminConsole.port | 9090 | |||
adminConsole.securePort | 9091 |
plugin.restapi.enabled | true | |||
plugin.restapi.httpAuth | basic |
xmpp.auth.anonymous | true | |||
xmpp.domain | localhost | |||
xmpp.httpbind.scriptSyntax.enabled | true | |||
xmpp.session.conflict-limit | 0 | |||
xmpp.socket.ssl.active | true |
然后:
让别人去把openfire中的domain,全部都统一称为对应的此处的IP地址:
192.168.1.110
然后我代码中再去测试,看看是否可行。
Openfire中domain的已经都改为IP了:
属性名 | 属性值 | 编辑 | 加密 | 删除 |
---|---|---|---|---|
admin.authorizedJIDs |
xmpp.domain | 192.168.1.110 |
另外,什么ElasticSearch说是也都更新domain为IP了。
然后代码即可正常执行了:
没有调用到(出错时才会执行的)didNotAuthenticate
而调用了:xmppStreamDidAuthenticate
[总结]
如此就说明:之前是由于XMPP服务器,此处的Openfire中的domain设置有误造成此问题的。
之前Openfire中的domain相关内容:
至少有:
admin.authorizedJIDs = [email protected],[email protected]
xmpp.domain =localhost
现在改为:
admin.authorizedJIDs = [email protected],[email protected]
xmpp.domain =192.168.1.110
其中,localhost改为XMPP服务器地址(Openfire所在服务器的IP地址:192.168.1.110)
之前和之后,各种XMPP客户端:
Spark,Mac的Aduim
都是可以正常登陆账号的
而此处的Mac开发中所用的,iOS的Swift的XMPP库:SwiftXMPP,中,对于之前的Openfire的domain是localhost的话:
对于代码来说:
登陆账号设置为:
还是:
xxx@服务器IP地址
结果都无法访问,因为:
如果代码中设置了[email protected],那么代码中将无法解析localhost为主机的IP地址,从而无法访问服务器
如果代码设置了xxx@服务器IP地址,那么会由于此处服务器IP是对了,使得代码可以连接服务器,但是却和服务器端的domain是localhost不匹配,从而导致JID不匹配出错:<failure xmlns=”urn:ietf:params:xml:ns:xmpp-sasl”><not-authorized/></failure>
解决办法很简单:
就是XMPP服务器,此处deOpenfire中,把xmpp的domain部分,原先是localhost,改为主机的IP地址(此处的192.168.1.110)
从:
admin.authorizedJIDs = [email protected],[email protected] xmpp.domain =localhost |
改为:
admin.authorizedJIDs = [email protected],[email protected] xmpp.domain =192.168.1.110 |
再重启XMPP服务器(Openfire),即可。
注:
此处顺带贴上,当前的Openfire的配置信息:
属性名 | 属性值 |
admin.authorizedJIDs | [email protected],[email protected] |
adminConsole.port | 9090 |
adminConsole.securePort | 9091 |
connectionProvider.className | org.jivesoftware.database.EmbeddedConnectionProvider |
httpbind.CORS.domains | * |
httpbind.CORS.enabled | TRUE |
httpbind.enabled | TRUE |
httpbind.forwarded.enabled | FALSE |
locale | zh_CN |
passwordKey | hidden |
plugin.restapi.allowedIPs | |
plugin.restapi.enabled | TRUE |
plugin.restapi.httpAuth | basic |
plugin.restapi.secret | r1TKsFJ6ivNB3722 |
provider.admin.className | org.jivesoftware.openfire.admin.DefaultAdminProvider |
provider.auth.className | org.jivesoftware.openfire.auth.DefaultAuthProvider |
provider.group.className | org.jivesoftware.openfire.group.DefaultGroupProvider |
provider.lockout.className | org.jivesoftware.openfire.lockout.DefaultLockOutProvider |
provider.securityAudit.className | org.jivesoftware.openfire.security.DefaultSecurityAuditProvider |
provider.user.className | org.jivesoftware.openfire.user.DefaultUserProvider |
provider.vcard.className | org.jivesoftware.openfire.vcard.DefaultVCardProvider |
setup | TRUE |
update.lastCheck | 1448418476089 |
xmpp.auth.anonymous | TRUE |
xmpp.domain | 192.168.1.110 |
xmpp.httpbind.scriptSyntax.enabled | TRUE |
xmpp.jmx.enabled | FALSE |
xmpp.jmx.port | 1099 |
xmpp.jmx.secure | TRUE |
xmpp.session.conflict-limit | 0 |
xmpp.socket.ssl.active | TRUE |
转载请注明:在路上 » [已解决]swift中XMPP连接出错: