IOS-XMPP Client

Source: Internet
Author: User

First we make an iOS client program ourselves

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

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.

Kkviewcontroller.m

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

Here is the chat page

The focus here is still uitableview.

Kkchatcontroller.m

These are relatively simple, I believe we should all be able to read

To facilitate program invocation, we write some of the main methods of XMPP in Appdelegate

Under APPDELEGATE.M These methods are:

These are the basic methods, the next is the method in Xmppstreamdelegate, is also an important way to accept the status of friends, receive messages

There are two delegate methods, one is the user list delegate, there is a message delegate, the user list is mainly to get online users, update user TableView, message delegation is to get the message sent by friends, and update the message TableView, Of course, these two tableview are in different controllers.

After defining the two delegates, we will implement the two delegates in different controllers.

Implement <KKChatDelegate> in your buddy controller and write the following method

Join in the Viewdidload

These two lines of code, let the Friend list of the delegate implementation method in this program

Join in the Viewwillappear

Determine if there is a userid in the locally saved data and skip to the login page if you don't have one.

The most important thing here is connect, this word is login this is the message we want to display, each message is a dictionary

And then there's the display of every message.

, if successful, the page will show your friends list.

Here's the chat controller.

Join in the KKChatController.h

This is the message we want to display, each message is a dictionary

And then there's the display of every message.

Like the above friend Controller, here we also need xmppstream

Join in the Viewdidload

Set a message delegate to receive and process it by itself

The next most important thing is to send a message.

Here is how we mainly describe how to beautify our chat program, look at the final effect, of course, the source program will be released at the end

Okay, let's take a look at the program we wrote.

Here we customize the Tableviewcell

One line is to display the release date, a line to display the messages sent, and a background

As defined, change the cell to our own defined cell in UITableViewCell.

In this cell, set the background of the message sent and the background map to receive the message.

There's a "time" in the dictionary here.

This is the time we receive and send messages

In the APPDELEGATE.M

We will also make adjustments to the contents of the message we receive.

Finally, let's set the height of each line.

, by the time you send a message, don't forget to add

IOS-XMPP Client

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.