The introduction of the server, this article we are going to focus on, write our own iOS client program
Let's look at what we've done.
First download the Xmppframework framework,
Click Zip to download
Next, create a new project with Xcode
Drag the following files into the new project
Join the framework
and set
Here we are all set up, run for a try, see if there is a mistake
If there is no mistake, our xmppframework will join in the success.
We set up our pages such as:
Our KKViewController.h.
#import <UIKit/UIKit.h>
@interface Kkviewcontroller:uiviewcontroller<uitableviewdelegate, uitableviewdatasource>
@property (Strong, nonatomic) Iboutlet UITableView *tview;
-(Ibaction) account: (ID) sender;
@end
Kkviewcontroller.m
#import "KKViewController.h"
@interface Kkviewcontroller () {
Online users
Nsmutablearray *onlineusers;
}
@end
@implementation Kkviewcontroller
@synthesize TView;
-(void) viewdidload
{
[Super Viewdidload];
Self.tView.delegate = self;
Self.tView.dataSource = self;
Onlineusers = [Nsmutablearray array];
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
The code here believe that you have learned uitableview words should be very familiar with, if you do not know, just check the simple application of UITableView learn it
Next is the login page
Kklogincontroller.m
-(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];
Save
[Defaults synchronize];
[Self dismissmodalviewcontrolleranimated:yes];
}else {
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Prompt" message:@ "Please enter user name, password and server" Delegate:nil Cancelbuttontitle: @ "OK" 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;
}
Here is the chat page
The focus here is still uitableview.
Kkchatcontroller.m
-(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;
}
These are relatively simple, I believe we should all be able to read
Set these all up, we are going to focus on XMPP, afraid too long, take the next chapter.
XMPP-based iOS chat client program (iOS side one)