一点一滴慢慢的揭开XMPP的神秘面纱
来源:互联网 发布:mathlab矩阵向量化 编辑:程序博客网 时间:2024/06/08 19:50
XMPP
是干嘛的在此就不多探讨了,我也是刚开始尝试着学习。
首先我们把XMPP
拉进工程,然后必须导入的几个框架: CFNetwork.framework
Security.framework
libxml2.dylib
libresolv.dylib
SystemConfiguration.framework
CoreLocation.framework
AudioToolbox.framework
AVFoundation.framework
运行下不报错就对了。。。。。
在我们开发中做聊天的话,我们首先是需要登陆,登陆之后获取用户的信息,
获取到信息之后我们判断下该用户是否已经在Openfire
存在,不存在就直接给用户注册,存在就自动赋值登陆Openfire
[self XmppLogin:dic];
更多经验请点击
#pragma mark 登陆xmpp-(void)XmppLogin:(NSDictionary*)userdic{ App.IM_Account = [NSString stringWithFormat:@"Bison%@",App.UserId];//拼上前缀 App.IM_Password = @"**************"; [[JEXMPP Shared] XmppLogin];}
#pragma mark - 登录 退出-(BOOL)XmppLogin{ if (![XMPP_Stream isDisconnected]) { return YES; } [XMPP_Stream setHostName:kIM_Host];//设置服务器 [XMPP_Stream setHostPort:[kIM_Port intValue]];//设置端口 NSLog(@"jid:%@ ps:%@",App.IM_Account,App.IM_Password); if (App.IM_Account == nil || App.IM_Password == nil) { return NO; } XMPPJID *myjid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",App.IM_Account,kIM_Domain] resource:@"jp"];//设置了 jid 的 resource 即限制了多点登陆 NSError *error ; [XMPP_Stream setMyJID:myjid]; if (![XMPP_Stream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) { NSLog(@"my connected error : %@",error.description); return NO; } return YES;}
接下来就是验证是否登陆了Openfire
//将要连上- (void)xmppStreamWillConnect:(XMPPStream *)sender{ NSLog(@"==xmppStreamWillConnect");}//连上了 还要验证密码- (void)xmppStreamDidConnect:(XMPPStream *)sender{ NSLog(@"xmppStreamDidConnect"); if (App.IM_Password) { NSError *error ; if (![XMPP_Stream authenticateWithPassword:App.IM_Password error:&error]) { NSLog(@"error authenticate : %@",error.description); } }}//突然掉线了- (void)xmppReconnect:(XMPPReconnect *)sender didDetectAccidentalDisconnect:(SCNetworkReachabilityFlags)reachabilityFlags { NSLog(@"didDetectAccidentalDisconnect : \n %u ", reachabilityFlags);}//YES 重连 - (BOOL)xmppReconnect:(XMPPReconnect *)sender shouldAttemptAutoReconnect:(SCNetworkReachabilityFlags)reachabilityFlags{ NSLog(@"shouldAttemptAutoReconnect : \n %u ", reachabilityFlags); return YES;}#pragma mark 发送 成功 失败- (void)xmppStream:(XMPPStream *)sender didSendMessage:(XMPPMessage *)message{}//发送失败- (void)xmppStream:(XMPPStream *)sender didFailToSendMessage:(XMPPMessage *)message error:(NSError *)error{}//发送 成功或失败的 反馈给聊天页面-(void)XmppSend_Status:(NSInteger)status Msg:(JEChatMessage *)msg{ NSLog(@"XmppSend_Status 消息发送:%@ \n内容:%@", status == 1 ? @"成功" : @"失败",msg.TextContent);}#pragma mark 接收消息- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message{ NSLog(@"%@\n 来新消息了\n from:%@\n to:%@\n type:%@\n message:%@\n body:%@",message,[[message attributeForName:@"from"] stringValue],[[message attributeForName:@"to"] stringValue],[[message attributeForName:@"type"] stringValue],[[message attributeForName:@"message"] stringValue],[[message elementForName:@"body"] stringValue]);}
今天暂时讲到这。。。。。
有不足之处希望大家指点出来哦,因为我也对xmpp刚接触不久
版权归©Bison所有 任何转载请标明出处!
博主app上线啦,快点此来围观吧
2 0
- 一点一滴慢慢的揭开XMPP的神秘面纱
- 揭开木马的神秘面纱
- 揭开Expect的神秘面纱
- 揭开IRC的神秘面纱
- 揭开Expect的神秘面纱
- 揭开木马的神秘面纱
- 揭开点穴的神秘面纱
- 揭开Winsock的神秘面纱
- 揭开SOCKET的神秘面纱
- 揭开主板的神秘面纱
- 揭开进程的神秘面纱
- 揭开Expect的神秘面纱
- 揭开MVC的神秘面纱
- 揭开计算机的神秘面纱
- 揭开计算机的神秘面纱
- 揭开Shellcode的神秘面纱
- 揭开LiteOS的神秘面纱
- 揭开runtime的神秘面纱
- mysql启动不了的问题总结
- IOS 四种保存数据的方式
- C++ traits萃取技术理解与实例
- 一段倒计时的代码
- iOS开发网络篇—HTTP协议
- 一点一滴慢慢的揭开XMPP的神秘面纱
- JSP页面中常用四种标签
- RMII模式以太网PHY芯片DP83848C的应用
- google面试题
- 关于序偶和二元关系的基本概念(摘自Wikipedia)
- matlab plot绘图
- CSS各种居中方法
- iOS开发网络篇—搭建本地服务器
- 后台获取 已存在的 ApplicationContext 对象