介绍完了服务器,这篇我们就要介绍重点了,写我们自己的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. Android 操作系统的内存回收机制

    参考 http://www.ibm.com/developerworks/cn/opensource/os-cn-android-mmry-rcycl/index.html

  2. 在VS2012中采用C++中调用DLL中的函数 (4)

    这两天因为需要用到VS2012来生成一个DLL代码,但是之前并没有用过DLL相关的内容,从昨天开始尝试调试DLL的文件调用,起初笔者在网络上找到了3片采用VSXXX版本进行调试的例子,相关的内容见本人 ...

  3. SVN与TortoiseSVN实战:补丁详解

    硬广:<SVN与TortoiseSVN实战>系列已经写了五篇,第二篇<SVN与TortoiseSVN实战:标签与分支>和第三篇<SVN与TortoiseSVN实战:Tor ...

  4. java值得注意的几个问题

    1.一个源文件中只能有一个类是public的,其他的都是默认权限的: 2.一个类只能作为public或者默认权限(就是没有修饰符的意思): 3.源文件的public类的名字必须要跟文件名保持一致,否则 ...

  5. 实现支持在Mac OS的最小大化的过渡效果

    实现支持在Mac OS的最小大化的过渡效果,该源码是刚刚在源码天堂那个网站上转载过来的,个人感觉还不错的,大家可以学习一下吧. 源码下载:http://code.662p.com/view/2250. ...

  6. 安装zabbix

    安装zabbix 1. 准备好lamp架构(安装好mysql,php) 2.在数据库中授权: MariaDB [(none)]> create database zabbix charset u ...

  7. C++ sstream 中处理字符串

    C++引入ostringstream.istringstream.stringstream这三个类,要使用他们创建对象就必须包含<sstream>这个头文件. istringstream的 ...

  8. javascript中substring()、substr()、slice()的区别

    在js字符截取函数有常用的三个slice().substring().substr()了,下面我来给大家介绍slice().substring().substr()函数在字符截取时的一些用法与区别吧. ...

  9. Windows Server 2008 R2 密码破解

    Win 2008 Server 忘记密码怎么办,不能像Win7/8/XP 那样用PE破解就只有这种方法了1.首先,把Windows 2008 的镜像放进去光驱我们用光驱启动     2. 这时候按下S ...

  10. <b>和<strong>标签区别

    简单说, strong是web标准中xhtml的标签,加强语气,起强调作用(默认是采用加粗来实现强调),逻辑标签: b 是html的,bold粗体. web标准主张xhtml不涉及具体的表现形式,“强 ...