日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[iPhone高级] 基于XMPP的IOS聊天客户端程序(IOS端一)

發(fā)布時間:2024/9/30 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [iPhone高级] 基于XMPP的IOS聊天客户端程序(IOS端一) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

介紹完了服務(wù)器,這篇我們就要介紹重點了,寫我們自己的IOS客戶端程序

先看一下我們完成的效果圖



首先下載xmppframework這個框架,下載


點ZIP下載

接下來,用Xcode新建一個工程

將以下這些文件拖入新建工程中



加入framework


并設(shè)置

到這里我們就全部設(shè)好了,跑一下試試,看有沒有錯呢

如果沒有錯的話,我們的xmppframework就加入成功了。


我們設(shè)置我們的頁面如下圖:


我們的KKViewController.h

[java]?view plaincopy
  • #import?<UIKit/UIKit.h>??
  • ??
  • @interface?KKViewController?:?UIViewController<UITableViewDelegate,?UITableViewDataSource>??
  • ??
  • @property?(strong,?nonatomic)?IBOutlet?UITableView?*tView;??
  • ??
  • -?(IBAction)Account:(id)sender;??
  • @end??

  • KKViewController.m

    [java]?view plaincopy
  • #import?"KKViewController.h"??
  • ??
  • @interface?KKViewController?(){??
  • ??????
  • ????//在線用戶??
  • ????NSMutableArray?*onlineUsers;??
  • ??????
  • }??
  • ??
  • @end??
  • ??
  • @implementation?KKViewController??
  • @synthesize?tView;??
  • ??
  • -?(void)viewDidLoad??
  • {??
  • ????[super?viewDidLoad];??
  • ????self.tView.delegate?=?self;??
  • ????self.tView.dataSource?=?self;??
  • ??????
  • ????onlineUsers?=?[NSMutableArray?array];??
  • ????//?Do?any?additional?setup?after?loading?the?view,?typically?from?a?nib.??
  • }??
  • ??
  • -?(void)viewDidUnload??
  • {??
  • ????[self?setTView:nil];??
  • ????[super?viewDidUnload];??
  • ????//?Release?any?retained?subviews?of?the?main?view.??
  • }??
  • ??
  • -?(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation??
  • {??
  • ????return?(interfaceOrientation?!=?UIInterfaceOrientationPortraitUpsideDown);??
  • }??
  • ??
  • -?(IBAction)Account:(id)sender?{??
  • }??
  • ??
  • #pragma?mark?UITableViewDataSource??
  • ??
  • -(NSInteger)tableView:(UITableView?*)tableView?numberOfRowsInSection:(NSInteger)section{??
  • ??????
  • ????return?[onlineUsers?count];??
  • }??
  • ??
  • -(UITableViewCell?*)tableView:(UITableView?*)tableView?cellForRowAtIndexPath:(NSIndexPath?*)indexPath{??
  • ??????
  • ????static?NSString?*identifier?=?@"userCell";??
  • ????UITableViewCell?*cell?=?[tableView?dequeueReusableCellWithIdentifier:identifier];??
  • ????if?(cell?==?nil)?{??
  • ????????cell?=?[[UITableViewCell?alloc]?initWithStyle:UITableViewCellStyleDefault?reuseIdentifier:identifier];??
  • ????}??
  • ??????
  • ??????
  • ????return?cell;??
  • ??????
  • ??????
  • }??
  • ??
  • -?(NSInteger)numberOfSectionsInTableView:(UITableView?*)tableView{??
  • ??????
  • ????return?1;??
  • }??
  • ??
  • #pragma?mark?UITableViewDelegate??
  • -(void)tableView:(UITableView?*)tableView?didSelectRowAtIndexPath:(NSIndexPath?*)indexPath{??
  • ??????
  • ??????
  • }??
  • ??
  • ??
  • @end??
  • 這里的代碼相信大家學(xué)過UITableView的話應(yīng)該很熟悉了,如果不知道的話,就查一下UITableView的簡單應(yīng)用學(xué)習(xí)一下吧

    接下來是登錄的頁面


    KKLoginController.m

    [java]?view plaincopy
  • -?(IBAction)LoginButton:(id)sender?{??
  • ??????
  • ????if?([self?validateWithUser:userTextField.text?andPass:passTextField.text?andServer:serverTextField.text])?{??
  • ??????????
  • ????????NSUserDefaults?*defaults?=?[NSUserDefaults?standardUserDefaults];??
  • ????????[defaults?setObject:self.userTextField.text?forKey:USERID];??
  • ????????[defaults?setObject:self.passTextField.text?forKey:PASS];??
  • ????????[defaults?setObject:self.serverTextField.text?forKey:SERVER];??
  • ????????//保存??
  • ????????[defaults?synchronize];??
  • ??????????
  • ????????[self?dismissModalViewControllerAnimated:YES];??
  • ????}else?{??
  • ????????UIAlertView?*alert?=?[[UIAlertView?alloc]?initWithTitle:@"提示"?message:@"請輸入用戶名,密碼和服務(wù)器"?delegate:nil?cancelButtonTitle:@"確定"?otherButtonTitles:nil,?nil];??
  • ????????[alert?show];??
  • ????}??
  • ??
  • }??
  • ??
  • -?(IBAction)closeButton:(id)sender?{??
  • ??????
  • ????[self?dismissModalViewControllerAnimated:YES];??
  • }??
  • ??
  • -(BOOL)validateWithUser:(NSString?*)userText?andPass:(NSString?*)passText?andServer:(NSString?*)serverText{??
  • ??????
  • ????if?(userText.length?>?0?&&?passText.length?>?0?&&?serverText.length?>?0)?{??
  • ????????return?YES;??
  • ????}??
  • ??????
  • ????return?NO;??
  • }??
  • 下面是聊天的頁面


    這里著重的還是UITableView

    KKChatController.m

    [java]?view plaincopy
  • -(NSInteger)numberOfSectionsInTableView:(UITableView?*)tableView{??
  • ??????
  • ????return?1;??
  • }??
  • ??
  • -(NSInteger)tableView:(UITableView?*)tableView?numberOfRowsInSection:(NSInteger)section{??
  • ????return?[messages?count];??
  • }??
  • ??
  • -(UITableViewCell?*)tableView:(UITableView?*)tableView?cellForRowAtIndexPath:(NSIndexPath?*)indexPath{??
  • ??????
  • ????static?NSString?*identifier?=?@"msgCell";??
  • ??????
  • ????UITableViewCell?*cell?=?[tableView?dequeueReusableCellWithIdentifier:identifier];??
  • ??????
  • ????if?(cell?==?nil)?{??
  • ????????cell?=?[[UITableViewCell?alloc]?initWithStyle:UITableViewCellStyleSubtitle?reuseIdentifier:identifier];??
  • ????}??
  • ??????
  • ????NSMutableDictionary?*dict?=?[messages?objectAtIndex:indexPath.row];??
  • ??????
  • ????cell.textLabel.text?=?[dict?objectForKey:@"msg"];??
  • ????cell.detailTextLabel.text?=?[dict?objectForKey:@"sender"];??
  • ????cell.accessoryType?=?UITableViewCellAccessoryNone;??
  • ??????
  • ????return?cell;??
  • ??????
  • }??
  • 這些都比較簡單,相信大家應(yīng)該都能看得懂

    把這些都設(shè)置好以后,我們就要著重介紹XMPP了,怕太長了,接下一章吧。

    總結(jié)

    以上是生活随笔為你收集整理的[iPhone高级] 基于XMPP的IOS聊天客户端程序(IOS端一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。