By using this website, you agree to our Cookies Policy


The past few years have brought messaging apps into the limelight. People have started to prefer chat-based applications for their regular interaction using modern technologies like swift, kotlin, etc.

However, this popularity has grabbed the attention of many developers and businesses to look out for something more on technology to build their own chat app for mobile and web apps.

Thus, in this tutorial I have made an attempt to bridge the gap that may arise in between, with a walk-through pointing out steps to build a quality chat app using one of the modern technologies of Swift for your existing iOS device with minimal effort.

List of Requirements to Build Chat App iOS with Swift

Let’s have a look at some of the minimal requirement for an iOS chat app - iOS 12.1

Before moving ahead with the technical part, it is very important to understand how MirrorFly actually works. This documentation will help you understand the concept much better than ever.

Initial Setup for iOS Chat App

To start with, before getting into the coding part of , it is essential to set up MirrorFly in your application. Now, once done with the same you have to follow some of the below steps.

  • Create your MirrorFly Pro account
  • Get your Applications SDK license key
  • Add the MirrorFly Dependency in your application by adding its Pod

Now, this initialization process starts with installation steps, which is followed by preliminary steps of Chat SDKs implementation.

SDK License Key

To use any SDK while planning to build an iOS chat app using swift technology, you must be assured about authentication checks as to whether your SDKs are authenticated by the MirrorFly server or not.

Moreover, to go with this authentication check make use of the master License Key which is there in your dashboard.

But be aware that the master API token can never be changed or revoked.

Installation process for iOS Chat App

To begin with the installation process, the file has to be imported into the project with the support of swift technology. This is carried out using some of the below steps,

Step 1 : Download the latest SDK from MirrorFly Control Panel Download section

Step 2 : Extract the needed file from downloadable zip file

Step 3 : Create a new iOS project or open an existing project

Step 4 : Now, add the following frameworks in your project's app folder

  • FlyCore.framework
  • FlyCommon.framework
  • FlyNetwork.framework
  • FlyDatabase.framework
  • FlyXmpp.framework

Step 5 : Choose the content of all the above frameworks that have been added to the project.

Step 6 : Then add the below dependencies that are needed by the SDK in Pods file

  • pod 'libPhoneNumber-iOS'
  • pod 'Alamofire'
  • pod 'RealmSwift'
  • pod 'XMPPFramework/Swift'

Let’s have a look at some of the terminologies in SDK with their explanation.

Keyword Explanation
userID/userBareID Unique ID assigned for each user Ex: 12345678 (any alphanumeric). The below characters is not allowed in userId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@) userID should follow below specification:
userJid (or) JID userID+@+domain of the chat server Ex.
groupID/groupBareID Unique ID assigned for each group Ex: group123456 (any alphanumeric). GroupJID = groupID +@mix.+domain of the chat server Ex:`

Now, the above are the regular steps that take place in all the chat app development. But let’s be specific about Swift technology in further.

Step-by-Step Build Your iOS Chat App using Swift

Initialize ChatSDK for iOS Chat App

To begin with initialization, you require certain basic data to get started with MirrorFly Chat SDK. In this tutorial, we make use of the ChatSDK class and AppDelegate class from 'didFinishlaunchingWithOptions' use them in the development process of your pre-existing iOS chat app using the below mentioned method.

                                            let groupConfig = try? GroupConfig.Builder
                                                            .enableGroupCreation(groupCreation: true)
                                                            .onlyAdminCanAddOrRemoveMembers(adminOnly: true)
                                                            .setMaximumMembersInAGroup(membersCount: 200)
                                            ChatSDK.Builder.enableMobileNumberLogin(isEnable: true)
                                                             .setDomainBaseUrl(baseUrl: "")
                                                            .setMaximumPinningForRecentChat(maxPinChat: 4)
                                                            .setGroupConfiguration(groupConfig: groupConfig!)
                                                            .deleteMediaFromDevice(delete: true)
                                                            .setAppGroupContainerID(containerID: "")

Functional Description to Build iOS Chat app

Function Parameter Type Description
enableMobileNumberLogin boolean true if mobile number is used as primary id for the user else false
setDomainBaseUrl String url needed for api calls provided by Chat team
setMaximumPinningForRecentChat Int maximum pin count in recent chat
setGroupConfiguration GroupConfig configuration for the group implementation
deleteMediaFromDevice boolean To show whether contact's profile name or nickname from sdk
setAppGroupContainerID String Pass group container id of the project to store UserDefaults and Database
buildAndInitialize n/a initialize the chat configuration

Function Description of a GroupConfig Builder during app development

Function Argument Type Description
enableGroupCreation boolean enable/disable group creation
setMaximumMembersInAGroup int set the maximum number of members a group can have(cannot be greater than 300)
onlyAdminCanAddOrRemoveMembers boolean if true only group admin can add/remove members else members can add/remove other members
build n/a build GroupConfig object

The initialization process is followed by,

  • Connect to the chat server
  • Set IV and Token for iOS chat app

Connect to the Chat Server

Once the initialization of your chat app development is done, there is a need to create a connection with the chat server which is possible by using server.sdk.

Here, this server.sdk stores all the connection details at a secure place and connects automatically whenever the app opens or closes.

Argument Type Description
USERNAME String userName for making connection to the server
SECRET_KEY String password used to authenticate to the xmpp server
XMPP_DOMAIN String domain name which will be used in jid
XMPP_HOST String xmpp server url
XMPP_PORT int port of the xmpp server

                          ChatManager.shared.initialize(username: USERNAME, 
                            secretKey:SECRET_KEY, xmppDomain: XMPP_DOMAIN, xmppPort: XMPP_PORT)  

After the initialization process, you have to create an immediate connection with your chat server only for the first time, later on you can simply forget about it.


Set IV and Token for iOS Chat App

Once the registration is called upon successfully using the below method, IV will pass the auth token to SDK.

Argument Type Description
IV String Initialization vector for data encryption and decryption
TOKEN String Auth token received during registration for making api calls

After which the functionalities like profile modules, single chat modules, etc., will be covered and dived deep into.

Keys of Profile Modules to be Noted While Building an iOS Chat App


Depending upon the version of your iOS, the syncing contact may work somewhat differently, so it’s better to have a check on that.

However, the iOS works with contact and syncing the phone book contacts from a variety of platforms using the below method easily.

                                ChatManager.shared.syncContacts(isFirstTime :true,completionHandler: { isSuccess, flyError, flyData in 
                                var data  = flyData
                                if isSuccess { 
                                    // Contact fetch successfully update the UI 
                                    } else{ 
                                         print(data.getMessage() as! String)

With ProfileDetails class tag, every single chat over here will be modelled and will store their user's data like display picture, blocked details, etc., at the most safe infrastructure.

Apart from syncing the contacts, the chat app has also provided access to the friends list, blocked contacts, removal of display images, etc.

Contact listed as friends

This is the screen that contains all the contacts that have been listed as friends, and the below program will enable you to have access to that list of contacts.

                              ContactManager.shared.getFriendsList(FETCH_FROM_SERVER){ isSuccess, flyError, flyData in

                                var data  = flyData

                                if isSuccess {
                                    let profileDetailsArray = data.getData() as! [ProfileDetails]
                                    } else{

Refer Class documentation to know about Profile Details Class

Argument Type Description
FETCH_FROM_SERVER Bool true to fetch from server false will fetch from local database
CALLBACK FlyCompletionHandler FlyCompletionHandler used as completion Handler

Single Chat Module You Need to Keep in Mind for your iOS Chat App-

Before you get started, there are some of the prerequisites that must be made a note of. Here, this tutorial will have a full-fledged coverage on the way MirrorFly works for iOS chat app development.

Well, where the basic functionality of a chat app is sending and receiving of messages, here will see how to call upon them to connect with the server for further communication.

In technical terms, before getting started with messages, the messaging features need to prepare a single chat jid. Here, jid is the input parameter which is provided by the SDKs using the chat config of [com.contuflysdk.api.ChatConnectionManager.initialize] method.

Note: The below characters is not allowed in uniqueId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@).

Argument Type Description
UNIQUE_USER_ID String unique userId for preparing JID

Now, let's have a look at different actions of these messaging features.

Text messages

As we know that text messages are the most basic form of interaction. The coding of chat SDK provides the syntax for the text messages to reach the end users.

Once the user receives the messages, it will give a callback with the current status somewhat like this,

                                           FlyMessenger.sendTextMessage(TO_JID, TEXT, REPLY_MESSAGE_ID){isSuccess,error,message in
                                               if isSuccess { 
                                                  // append message in your array and the  update ui
                                                 // reset the message TextField UI
Argument Type Description
TO_JID String jid of the end user
MESSAGE String Text message to be sent
REPLY_MESSAGE_ID String if it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACK FlySendMessageListener callback to observe the action status

All Time’s Need, The Group Chat Module for Your iOS Chat App

When you are interacting in a group, it will not work out to chat with a specific user, instead this place demands group chat communication to have everyone on the same page.

Here, the chat SDK connects your and the end users with the server by initializing the connection configuration and making the connection live.

As in the case for single chat module, even here you have to prepare group jid using the tag JID.FlyUtils.getGroupJid(groupId : String)

Note: The below characters is not allowed in uniqueId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@).

Argument Type Description
groupId String unique groupId for preparing group JID
groupName String Name of the group (cannot be null or empty)
participantJidList [String] Array of jids of the member (size cannot be less than 2 excluding group creator)
groupImageFileUrl String local file url of the image (can be empty)
completionHandler FlyCompletionHandler implemented as closure expression


During the tutorial, you would have got to learn many aspects of chat features that you can have in your iOS chat app. All this starting from text messages to group messages, then notification indicators to updates/removal of display images etc. Whatever be the case you have a specific tag to call the functions upon.

But, if you feel you need more clarity with more advanced features, feel free to drop your comments. I will have another in-depth detailed blog tutorial for you if necessary with swift technology to assist you to build your iOS chat app the most perfect way ever as you want!

As of now, I hope this tutorial will help you to give your users a better iOS chat experience.

Launch your Own iOS Chat App with Swift!

Get Started with MirrorFly SDK's and Improve your overall in-app conversion, engagement, and retention.

  • Average API response 3s
  • 100ms worldwide latency
  • 1 Billion +concurrent users
Start a free trial
Try MirrorFly Free for 21 Days!

It’s easy, free, and you can start integrating on your app immediately...

Start a free trial
Let's Talk To Sales Team

We’d love to answer your questions. Tell us your needs, and we’ll contact you shortly.

Talk to Sales