介绍完了服务器,这篇我们就要介绍重点了,写我们自己的IOS客户端程序

先看一下我们完成的效果图

首先下载xmppframework这个框架,下载

点ZIP下载

接下来,用Xcode新建一个工程

将以下这些文件拖入新建工程中

加入framework

并设置

到这里我们就全部设好了,跑一下试试,看有没有错呢

如果没有错的话,我们的xmppframework就加入成功了。

我们设置我们的页面如下图:

我们的KKViewController.h

  1. # import  <UIKit/UIKit.h>
  2. @interface  KKViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
  3. @property  (strong, nonatomic) IBOutlet UITableView *tView;
  4. - (IBAction)Account:(id)sender;
  5. @end

KKViewController.m

  1. # import   "KKViewController.h"
  2. @interface  KKViewController (){
  3. //在线用户
  4. NSMutableArray *onlineUsers;
  5. }
  6. @end
  7. @implementation  KKViewController
  8. @synthesize  tView;
  9. - (void )viewDidLoad
  10. {
  11. [super  viewDidLoad];
  12. self.tView.delegate = self;
  13. self.tView.dataSource = self;
  14. onlineUsers = [NSMutableArray array];
  15. // Do any additional setup after loading the view, typically from a nib.
  16. }
  17. - (void )viewDidUnload
  18. {
  19. [self setTView:nil];
  20. [super  viewDidUnload];
  21. // Release any retained subviews of the main view.
  22. }
  23. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  24. {
  25. return  (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  26. }
  27. - (IBAction)Account:(id)sender {
  28. }
  29. #pragma mark UITableViewDataSource
  30. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  31. return  [onlineUsers count];
  32. }
  33. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  34. static  NSString *identifier = @ "userCell" ;
  35. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  36. if  (cell == nil) {
  37. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  38. }
  39. return  cell;
  40. }
  41. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  42. return   1 ;
  43. }
  44. #pragma mark UITableViewDelegate
  45. -(void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  46. }
  47. @end

这里的代码相信大家学过UITableView的话应该很熟悉了,如果不知道的话,就查一下UITableView的简单应用学习一下吧

接下来是登录的页面

KKLoginController.m

  1. - (IBAction)LoginButton:(id)sender {
  2. if  ([self validateWithUser:userTextField.text andPass:passTextField.text andServer:serverTextField.text]) {
  3. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  4. [defaults setObject:self.userTextField.text forKey:USERID];
  5. [defaults setObject:self.passTextField.text forKey:PASS];
  6. [defaults setObject:self.serverTextField.text forKey:SERVER];
  7. //保存
  8. [defaults synchronize];
  9. [self dismissModalViewControllerAnimated:YES];
  10. }else  {
  11. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"  message:@ "请输入用户名,密码和服务器"  delegate:nil cancelButtonTitle:@ "确定"  otherButtonTitles:nil, nil];
  12. [alert show];
  13. }
  14. }
  15. - (IBAction)closeButton:(id)sender {
  16. [self dismissModalViewControllerAnimated:YES];
  17. }
  18. -(BOOL)validateWithUser:(NSString *)userText andPass:(NSString *)passText andServer:(NSString *)serverText{
  19. if  (userText.length >  0  && passText.length >  0  && serverText.length >  0 ) {
  20. return  YES;
  21. }
  22. return  NO;
  23. }

下面是聊天的页面

这里着重的还是UITableView

KKChatController.m

  1. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  2. return   1 ;
  3. }
  4. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  5. return  [messages count];
  6. }
  7. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  8. static  NSString *identifier = @ "msgCell" ;
  9. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  10. if  (cell == nil) {
  11. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
  12. }
  13. NSMutableDictionary *dict = [messages objectAtIndex:indexPath.row];
  14. cell.textLabel.text = [dict objectForKey:@"msg" ];
  15. cell.detailTextLabel.text = [dict objectForKey:@"sender" ];
  16. cell.accessoryType = UITableViewCellAccessoryNone;
  17. return  cell;
  18. }

这些都比较简单,相信大家应该都能看得懂

把这些都设置好以后,我们就要着重介绍XMPP了,怕太长了,接下一章吧。

[iPhone高级] 基于XMPP的IOS聊天客户端程序(IOS端一)的更多相关文章

  1. 基于XMPP的IOS聊天客户端程序

    简介:XMPP协议是一种基于Socket长连接.以XML格式进行基本信息交换.C/S S/S多种架构的聊天协议 XMPPServer 基于XMPP协议的服务端(例如eJabber.OpenFire) ...

  2. c++下基于windows socket的服务器客户端程序(基于UDP协议)

    前天写了一个基于tcp协议的服务器客户端程序,今天写了一个基于UDP协议的,由于在上一篇使用TCP协议的服务器中注释已经较为详细,且许多api的调用是相同的,故不再另外注释. 使用UDP协议需要注意几 ...

  3. 基于 JavaFX 开发的聊天客户端 OIM-即时通讯

    OIM 详细介绍 一.简介 OIM是一套即时通讯的聊天系统,在这里献给大家,一方面希望能够帮助对即时通讯有兴趣研究的朋友,希望我们能够共同进步,另一个就是希望能够帮助到需要即时通讯系统的朋友或者企业, ...

  4. 基于select的python聊天室程序

    python网络编程具体参考<python select网络编程详细介绍>. 在python中,select函数是一个对底层操作系统的直接访问的接口.它用来监控sockets.files和 ...

  5. 基于 SailingEase WinForm Framework 开发客户端程序(3:实现菜单/工具栏按钮的解耦及状态控制)

    本系列文章将详细阐述客户端应用程序的设计理念,实现方法. 本系列文章以  SailingEase WinForm Framework 为基础进行设计并实现,但其中的设计理念及方法,亦适用于任何类型的客 ...

  6. 高级IO复用应用:聊天室程序

    简单的聊天室程序:客户端从标准输入输入数据后发送给服务端,服务端将用户发送来的数据转发给其它用户.这里采用IO复用poll技术.客户端采用了splice零拷贝.服务端采用了空间换时间(分配超大的用户数 ...

  7. 浏览器网页判断手机是否安装IOS/Android客户端程序

    IOS 原理如下: 为HTML页面中的超链接点击事件增加一个setTimeout方法. 如果在iPhone上面500ms内,本机有应用程序能解析这个协议并打开程序,则这个回调方法失效: 如果本机没有应 ...

  8. 浏览器判断是否安装了ios/android客户端程序

    最近在做一个项目,该项目的前身是为mobile browser量身打造的一个网站.现在有这样一个需求: 当用户在用mobile browser浏览该网站的时候会点击一个按钮/超链接,通过这个按钮的点击 ...

  9. 基于XMPP协议的Android即时通信系

    以前做过一个基于XMPP协议的聊天社交软件,总结了一下.发出来. 设计基于开源的XMPP即时通信协议,采用C/S体系结构,通过GPRS无线网络用TCP协议连接到服务器,以架设开源的Openfn'e服务 ...

随机推荐

  1. shell脚本循环执行mysql语句

    参考资料:Shell脚本中执行mysql语句 需求:数据库里有张数据表存储的是用户对电影的评价(user_id movie_id rating time),但是我现在要每部电影的总评分. 解决方法: ...

  2. Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance 7d90eb80-29e2-4238-b658-ade407ff9456. Last exception: [u'Traceback (most recent call last):\n', u' File "/usr/lib/py

    Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance 7d90eb80-29e2-42 ...

  3. ASP.NET的SEO:HTTP报头状态码---内容重定向

    本系列目录 我们经常说"404错误",你知道他指的是什么意思么? 404其实是Http报头所包含的一个"状态码",表明该Http请求失败.那么除此之外,还有哪些 ...

  4. poj3692_Kindergarten

    这题目大意是:男孩互相认识,女孩互相认识,一部分男女之间认识,老师要选一部分人,要求这部分人必须都相互认识. 这是一个二部图,先求出补图,在补图中G‘左右两点有连线说明在G中两者不认识,反之成立. 所 ...

  5. Data URL

    Data URL 早在 1995 年就被提出,那个时候有很多个版本的 Data URL Schema 定义陆续出现在 VRML 之中,随后不久,其中的一个版本被提上了议案——将它做个一个嵌入式的资源放 ...

  6. 二、搭建struts2的开发环境

    二.搭建struts2的开发环境 下载地址:http://struts.apache.org 解压后的目录结构: apps:框架本身提供一些案例(学习) docs:框架本身提供的文档(指南和API). ...

  7. c++强制类型转换(static_cast,const_cast,dynamic_cast,reinterpret_cast)

    static_cast <typeid>(exdlvssion) static_cast 很像 C 语言中的旧式类型转换.它能进行基础类型之间的转换,也能将带有可被单参调用的构造函数或用户 ...

  8. c#中操作word文档-一、模板方式写入

    转载自:http://blog.csdn.net/fujie724/article/details/5443322 适合模板写入 今天正好有人问我,怎么生成一个报表式的Word文档. 就是文字的样式和 ...

  9. GoldenGate中使用FILTER,COMPUTE 和SQLEXEC命令

    本文主要介绍OGG中一些过滤或计算函数的用法,以及sqlexec的基本用法 SQLPREDICATE 在使用OGG初始化时,可以添加此参数到extract中,用于选择符合条件的记录,下面是OGG官方文 ...

  10. Windows7防火墙服务无法启用怎么办

    点击windows 7控制面板中防火墙的“推荐配置”没有反应,打开“服务”,无法启动windows firewall,并报错.  问题:  1.点击windows 7控制面板中防火墙的“推荐配置”没有 ...