[iphone advanced] XMPP-based iOS chat client program (iOS side One)

Source: Internet
Author: User

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, download

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.

[Java]View Plain Copy
    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

[Java]View Plain Copy
  1. # Import "KKViewController.h"
  2. @interface Kkviewcontroller () {
  3. //Online users
  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. 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

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

[Java]View Plain Copy
  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. //Save
  8. [Defaults synchronize];
  9. [Self dismissmodalviewcontrolleranimated:yes];
  10. }Else {
  11. Uialertview *alert = [[Uialertview alloc] initwithtitle:@"Prompt" message:@ "Please enter user name, password and server" Delegate:nil Cancelbutt   ontitle:@ "OK" 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. }

Here is the chat page

The focus here is still uitableview.

Kkchatcontroller.m

[Java]View Plain Copy
  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. }

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.

[iphone advanced] XMPP-based iOS chat client program (iOS side One)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.