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开发经常因某些因素会出现一些意想不到的错误, ...
随机推荐
- React使用笔记2-React Components的生命周期
Date: 2015-11-27 21:23 Category: Web Tags: JavaScript Author: 刘理想 [toc] 1. React Components的生命周期 Rea ...
- IOS 表视图(UITableVIew)的使用方法(4)自定义表视图单元
UITableViewCell的自定义往往需要自建一个UITableViewCell的子类后进行作业.开发者可以选择通过xib或者直接在UITableViewCell的布局中进行UITableView ...
- [转]IOS 学习笔记(8) 滚动视图(UIScrollView)的使用方法
下面介绍pageControl结合ScrollView实现连续滑动翻页的效果,ScrollView我们在应用开发中经常用到,以g这种翻页效果还是很好看的,如下图所示: 通过这个例子,我们重点学习UIS ...
- 阻止系统自动睡眠的小软件,附C#制作过程
原文 http://www.cnblogs.com/h46incon/p/SleepPreventer.html 因为有时下载东西的时候,不想让电脑自动深入睡眠,所以就开启了离开模式.这样不但不节能环 ...
- perl lwp 超时问题
lwp 超时问题: jrhmpt01:/root/async# cat a1.pl use LWP::UserAgent; use utf8; use DBI; use POSIX; use Data ...
- 一个异或加密方案--C语言实现
核心代码: char encrypt( char f , char c) { return f^c; } int OutEncrypt( char *FilePath, char *SecretWor ...
- [cocos2d-x]用CCSpriteBatchNode进行文理贴图的优化
引言: 我们在进行手机游戏开发的过程中,由于手机的内存资源是有限的,那么对纹理贴图的优化是非常有必要的,有可能相同的功能,优化的好与不好对内存资源的消耗是非常明显的,下面我就用一个例子来说明一下. 说 ...
- Qt5官方demo分析集11——Qt Quick Particles Examples - Affectors
在这个系列中的所有文章都可以在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集10--Qt ...
- 编写可维护的JavaScript—语句和表达式&变量、函数和运算符
语句和表达式 所有的块语句都应当使用花括号.包括: if for while do…while… try…catch…finally //不好的写法 if (condition) doSomethin ...
- js 特效 手风琴效果
$(document).ready(function(){ //定义展开的块 var lastBlock = $('#a1'); //展开的块的宽度 var maxWidth = 406; //折叠的 ...