在XMPP开发中,使用XMPPStream进行连接服务器后,验证过程中,比较常见的一个错误是

<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>.

尤其作为初学者(笔者就是这样的),经常会因为这个问题浪费不少时间。

xmpp的使用

1、创建xmppStream

  1. - (void)setupXmppStream
  2. {
  3. // 1. 实例化
  4. _xmppStream = [[XMPPStream alloc] init];
  5. [_xmppStream addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
  6. }

2、连接服务器

  1. - (void)connect
  2. {
  3. // 1. 实例化XMPPStream
  4. [self setupXmppStream];
  5. NSString *hostName = @"sky.local";
  6. //    NSString *hostName = @"127.0.0.1";
  7. NSString *userName = @"zhaoliu";
  8. // 设置XMPPStream的hostName&JID
  9. _xmppStream.hostName = hostName;
  10. _xmppStream.myJID = [XMPPJID jidWithUser:userName domain:hostName resource:nil];
  11. // 连接
  12. NSError *error = nil;
  13. if (![_xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
  14. NSLog(@"%@", error.localizedDescription);
  15. } else {
  16. NSLog(@"发送连接请求成功");
  17. }
  18. }

3、得到服务器相应后回调方法

  1. #pragma mark - XMPPStream协议代理方法
  2. #pragma mark 完成连接
  3. - (void)xmppStreamDidConnect:(XMPPStream *)sender
  4. {
  5. NSLog(@"success userName = %@, myJID = %@",sender.myJID.user, sender.myJID);
  6. // 登录到服务器,将用户密码发送到服务器验证身份
  7. NSString *password = @"123";
  8. [_xmppStream authenticateWithPassword:password error:nil];
  9. }
  10. #pragma mark 断开连接
  11. - (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error
  12. {
  13. NSLog(@"断开连接");
  14. }

4、登陆信息回调方法(即:[_xmppStream authenticateWithPassword:password error:nil]利用此方法发送密码到服务器完成登陆)

  1. #pragma mark 身份验证成功
  2. - (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
  3. {
  4. NSLog(@"身份验证成功!");
  5. }
  6. #pragma mark 用户名或者密码错误
  7. - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(DDXMLElement *)error
  8. {
  9. NSLog(@"用户名或者密码错误 error = %@",error);
  10. }

此时如果代码中的domain与openfire服务器中的设置不一样时,就会导致此错误,虽然我们用一些第三方客户端时一样能登陆成功

  1. NSString *hostName = @"sky.local";
  2. 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>)的更多相关文章

  1. XMPP 常见错误:<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>

    一般登陆/注册 出错,会在认证失败这里打印出error信息 - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(DDXMLEleme ...

  2. XMPP 常见错误:(<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-autho

    1检查jid XMPP认证的问题,一般都是与JID有关的,因此解决这类问题,首选的入口就是分析一下XMPPStream的JID,客户端在与服务器连接后,Socket就绑定了这个端口,用来处理与服务器的 ...

  3. iOS开发过程中常见错误问题及解决方案

    错误原因:ld: x duplicate symbol for architecture x86_64 clang: error: linker command failed with exit co ...

  4. xmpp 常见错误 一

    #pragma mark - 密码错误,身份验证失败 - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(DDXMLElement ...

  5. xmpp笔记2(客户端到服务器的例子)--xml

    xmpp( 客户端到服务器的例子 ) 1 步:客户端初始流给服务器: <stream:stream xmlns='jabber:client' xmlns:stream='http://ethe ...

  6. ios开发——错误总结篇&开发中常见错误和警告总结(四)

    ios开发——开发总结&开发中常见错误和警告总结(四) 网易彩票实战总结(错误) 错误总结之类的实现 经典错误之重复定义与导入错误 经典错误关于父类的实现 通知对象: 控制器的定义 Xcode ...

  7. iOS开发总结-Xcode常见错误

    iOS开发总结-Xcode常见错误 "file/file.h"filenotfound 如果遇到这种类型的问题报错,可以分为三部来解决,由简到复杂一步一步来,直到解决问题位置. 1 ...

  8. 李洪强iOS开发之OC常见错误汇总

    // //  main.m //  16 - 常见错误汇总 // //  Created by vic fan on 16/7/13. //  Copyright © 2016年 李洪强. All r ...

  9. Android NDK 开发(三)--常见错误锦集合Log的使用【转】

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/41826511  Android NDK开发经常因某些因素会出现一些意想不到的错误, ...

随机推荐

  1. React使用笔记2-React Components的生命周期

    Date: 2015-11-27 21:23 Category: Web Tags: JavaScript Author: 刘理想 [toc] 1. React Components的生命周期 Rea ...

  2. IOS 表视图(UITableVIew)的使用方法(4)自定义表视图单元

    UITableViewCell的自定义往往需要自建一个UITableViewCell的子类后进行作业.开发者可以选择通过xib或者直接在UITableViewCell的布局中进行UITableView ...

  3. [转]IOS 学习笔记(8) 滚动视图(UIScrollView)的使用方法

    下面介绍pageControl结合ScrollView实现连续滑动翻页的效果,ScrollView我们在应用开发中经常用到,以g这种翻页效果还是很好看的,如下图所示: 通过这个例子,我们重点学习UIS ...

  4. 阻止系统自动睡眠的小软件,附C#制作过程

    原文 http://www.cnblogs.com/h46incon/p/SleepPreventer.html 因为有时下载东西的时候,不想让电脑自动深入睡眠,所以就开启了离开模式.这样不但不节能环 ...

  5. perl lwp 超时问题

    lwp 超时问题: jrhmpt01:/root/async# cat a1.pl use LWP::UserAgent; use utf8; use DBI; use POSIX; use Data ...

  6. 一个异或加密方案--C语言实现

    核心代码: char encrypt( char f , char c) { return f^c; } int OutEncrypt( char *FilePath, char *SecretWor ...

  7. [cocos2d-x]用CCSpriteBatchNode进行文理贴图的优化

    引言: 我们在进行手机游戏开发的过程中,由于手机的内存资源是有限的,那么对纹理贴图的优化是非常有必要的,有可能相同的功能,优化的好与不好对内存资源的消耗是非常明显的,下面我就用一个例子来说明一下. 说 ...

  8. Qt5官方demo分析集11——Qt Quick Particles Examples - Affectors

    在这个系列中的所有文章都可以在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集10--Qt ...

  9. 编写可维护的JavaScript—语句和表达式&变量、函数和运算符

    语句和表达式 所有的块语句都应当使用花括号.包括: if for while do…while… try…catch…finally //不好的写法 if (condition) doSomethin ...

  10. js 特效 手风琴效果

    $(document).ready(function(){ //定义展开的块 var lastBlock = $('#a1'); //展开的块的宽度 var maxWidth = 406; //折叠的 ...