iOS XMPP之常见错误一:(<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>)
在XMPP开发中,使用XMPPStream进行连接服务器后,验证过程中,比较常见的一个错误是
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>.
尤其作为初学者(笔者就是这样的),经常会因为这个问题浪费不少时间。
xmpp的使用
1、创建xmppStream
- - (void)setupXmppStream
- {
- // 1. 实例化
- _xmppStream = [[XMPPStream alloc] init];
- [_xmppStream addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
- }
2、连接服务器
- - (void)connect
- {
- // 1. 实例化XMPPStream
- [self setupXmppStream];
- NSString *hostName = @"sky.local";
- // NSString *hostName = @"127.0.0.1";
- NSString *userName = @"zhaoliu";
- // 设置XMPPStream的hostName&JID
- _xmppStream.hostName = hostName;
- _xmppStream.myJID = [XMPPJID jidWithUser:userName domain:hostName resource:nil];
- // 连接
- NSError *error = nil;
- if (![_xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
- NSLog(@"%@", error.localizedDescription);
- } else {
- NSLog(@"发送连接请求成功");
- }
- }
3、得到服务器相应后回调方法
- #pragma mark - XMPPStream协议代理方法
- #pragma mark 完成连接
- - (void)xmppStreamDidConnect:(XMPPStream *)sender
- {
- NSLog(@"success userName = %@, myJID = %@",sender.myJID.user, sender.myJID);
- // 登录到服务器,将用户密码发送到服务器验证身份
- NSString *password = @"123";
- [_xmppStream authenticateWithPassword:password error:nil];
- }
- #pragma mark 断开连接
- - (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error
- {
- NSLog(@"断开连接");
- }
4、登陆信息回调方法(即:[_xmppStream authenticateWithPassword:password error:nil]利用此方法发送密码到服务器完成登陆)
- #pragma mark 身份验证成功
- - (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
- {
- NSLog(@"身份验证成功!");
- }
- #pragma mark 用户名或者密码错误
- - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(DDXMLElement *)error
- {
- NSLog(@"用户名或者密码错误 error = %@",error);
- }
此时如果代码中的domain与openfire服务器中的设置不一样时,就会导致此错误,虽然我们用一些第三方客户端时一样能登陆成功
- NSString *hostName = @"sky.local";
- NSString *hostName = @"127.0.0.1";
当我用adium、spark等第三方软件时,上面的两个都可以登陆成功。但是用代码时,则第一个就会<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>报错。提示没有注册、从登陆成功。原因是第一个设置与我opnefire服务器中的设置不一样导致。
下面看一下我openfire中的设置
http://blog.csdn.net/sky_2016/article/details/40278661
iOS XMPP之常见错误一:(<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>)的更多相关文章
- XMPP 常见错误:<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
一般登陆/注册 出错,会在认证失败这里打印出error信息 - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(DDXMLEleme ...
- XMPP 常见错误:(<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-autho
1检查jid XMPP认证的问题,一般都是与JID有关的,因此解决这类问题,首选的入口就是分析一下XMPPStream的JID,客户端在与服务器连接后,Socket就绑定了这个端口,用来处理与服务器的 ...
- iOS开发过程中常见错误问题及解决方案
错误原因:ld: x duplicate symbol for architecture x86_64 clang: error: linker command failed with exit co ...
- xmpp 常见错误 一
#pragma mark - 密码错误,身份验证失败 - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(DDXMLElement ...
- xmpp笔记2(客户端到服务器的例子)--xml
xmpp( 客户端到服务器的例子 ) 1 步:客户端初始流给服务器: <stream:stream xmlns='jabber:client' xmlns:stream='http://ethe ...
- ios开发——错误总结篇&开发中常见错误和警告总结(四)
ios开发——开发总结&开发中常见错误和警告总结(四) 网易彩票实战总结(错误) 错误总结之类的实现 经典错误之重复定义与导入错误 经典错误关于父类的实现 通知对象: 控制器的定义 Xcode ...
- iOS开发总结-Xcode常见错误
iOS开发总结-Xcode常见错误 "file/file.h"filenotfound 如果遇到这种类型的问题报错,可以分为三部来解决,由简到复杂一步一步来,直到解决问题位置. 1 ...
- 李洪强iOS开发之OC常见错误汇总
// // main.m // 16 - 常见错误汇总 // // Created by vic fan on 16/7/13. // Copyright © 2016年 李洪强. All r ...
- Android NDK 开发(三)--常见错误锦集合Log的使用【转】
转载请注明出处:http://blog.csdn.net/allen315410/article/details/41826511 Android NDK开发经常因某些因素会出现一些意想不到的错误, ...
随机推荐
- selenium 学习笔记 ---新手学习记录(1) 问题总结
说明:每次学习各种语言时,环境搭建访问国外网址最头疼了,现在只要是工具下载好放到自己网盘,可以随时用. 1.首先工具准备,selenium需要用到的 下载地址 访问密码 ff8f 2.我选择的语言时j ...
- struts2 taglib struts标签学习整理中
项目中经常会用到struts标签,这样可以减少代码量. select用法: <s:select list="#request.sysTypes" name="rul ...
- Tomcat embed
http://www.iflym.com/index.php/code/use-embeded-tomcat-to-javaee-start-tomcat.html http://java.dzone ...
- DropDownList控件学习
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 盘点:移动服务 #AzureChat
感谢大家帮助我们顺利推出史无前例的 #AzureChat.移动服务和 Notification Hub 是 Windows Azure 平台上令人振奋的服务.我们很高兴能借这次在线讨论的机会,倾听各位 ...
- Eclipse快捷键 今天又学会了几个不常用的 收藏了
1.Ctrl+e 打开所有已经打开的文件列表,当你使用Eclipse打开了N多文件的时候,需要找到一个你之前打开过 的文件,是不是就很费 ...
- phpmyadmin出现空password登录被禁止
在Windows或者Linux下mysql安装后默认的password为空,又当我们又安装了mysql的管理工具 phpmyadmin后登陆时出现"空password登陆呗禁止(參见同意pa ...
- Cstyle的札记,Freertos内核具体解释,第0篇
Freertos是一个硬实时内核,支持众多的微处理器架构,我们能够从它的官网(www.freertos.ort)下载它的sourcecode,同一时候也能够看出它支持了几十种的微处理器架构,这 ...
- MVC DI
using System;using Microsoft.Practices.Unity; public class BizInstanceFactory { private static reado ...
- 如何查看程序被哪个版本编译器编译的linux-gcc
如何查看程序被哪个版本编译器编译的linux-gcc http://bbs.csdn.net/topics/380000949 那是不可能的,除非你加入了调试信息,也就是编译的时候加入了-g参数,然后 ...