Let's integrate our SDK in few minutes

Quick Start#

MirrorFly Chat SDK V3 is released. Check out our latest Chat SDK V3 here.

To migrate from MirrorFly Chat SDK V2 to V3 please follow the Migration guide steps.

Chat SDKs for iOS#

With CONTUS MirrorFly Chat SDK for iOS, you can easily add real-time chat features to your client app within 30 minutes.

Through our client SDK, you can initialize and configure chat into your app with minimal efforts.

Note : If you're looking for the fastest way to build your app’s UI with MirrorFly Chat SDKs, you can use our sample apps. To get our sample apps, click here

Getting Started#


The below are the requirements for chat SDK for iOS,

  • Xcode 14.1 or later
  • iOS 13.0 or later
  • Swift 5.0 or later

Things To Be Noted Before You Get Started#

SDK License Key#

To integrate MirrorFly Chat SDK into your app, you will need a SDK License Key. The MirrorFly server will use this license key to authenticate the SDK in your application.

To get the License Key,#

Step 1: Register here to get a MirrorFly User account. Registration is subject to verification and would take up to 24 hours.

Step 2: Login to your Account

Step 3: Get the License key from the application Info’ section

Step 4: Download the iOS SDK


Integrate the Chat SDK#

Step 1: Add the following ChatSDK pod to your Podfile. If pod hasn't been initialised yet means, create a Podfile by executing pod init command.

pod 'MirrorFlySDK', '5.9.8'

Step 2: Add the below given pod hook code block at the end of the pod file and thus, finally install the pods by executing pod install command.

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'


Step 3 : Now, disable the bitcode for your project

Goto Project -> Build Settings -> Filter the term `Bitcode` -> and select No from the dropdown


Step 4 : Now, enable all the below mentioned capabilities into your project.

Goto Project -> Target -> Signing & Capabilities -> Click + at the top left corner -> Search for the capabilities below
Background Modes

Now, go to the background mode and enable the below given modes

Background Modes
Audio,Airplay, and Picture in Picture
Background fetch
Remote notifications

Configure the SDK server & Data#

Now, configure the server details in SDK and access the data globally using the AppDelegate class.

You can copy the license key from the 'Overview’ section in the Console dashboard.

let BASE_URL = "https://api-preprod-sandbox.mirrorfly.com/api/v1/"
let LICENSE_KEY = "xxxxxxxxxxxxxxxxxxxxxx"

Initialize ChatSDK#

To start using the sdk, there are a few basic pieces of data that must be made available for the SDKs to function perfectly.

Thus, we utilize the usage of the ChatSDK builder class making the data available for SDKs. Furthermore, in your project you must use the AppDelegate class within the didFinishLaunchingWithOptions method and also provide required data to build the ChatSDK Builder. Let's have a look at the example given below.

try? ChatSDK.Builder
.setLicenseKey(key: LICENSE_KEY)
.isTrialLicense(isTrial: true)
.setDomainBaseUrl(baseUrl: BASE_URL)


Chat Builder Function Description#

FunctionParameter TypeDescription
setLicenseKeyStringUsed to proceed with Registration
isTrialLicenseBoolIf the obtained license key is a trial license key - display the message as true else false
setDomainBaseUrlStringUrl required to make API calls
buildAndInitializen/aInitialize the chat configuration

The base url must have Http/Https protocol which should be closed with a slash (/), or else will display an exception bug message.


The below method should be called to register a new user. This method will take care of both Sandbox mode registration as well as Live mode registration based on isTrialLicense provided in the ChatSDK.Builder class.


Unless you logged out of a session, make sure that you have called the Registration method only once in an application

Note: While registration, the below registerApiService method will accept the additional params required for notification processing on server APNS_DEVICE_TOKEN, VOIP_TOKEN, IS_EXPORT and IS_FORCE_REGISTER as an optional param for maintaining sessions, USER_TYPE as an optional param to provide type of user and META_DATA as an optional param to provide MetaData of user.

try! ChatManager.registerApiService(for: USER_IDENTIFIER ) { isSuccess, flyError, flyData in
var data = flyData
if isSuccess {
// This is your Password
guard let password = data["password"] as? String else{
// This is your Username
guard let username = data["username"] as? String else{
let error = data.getMessage()
print("#chatSDK \(error)")
USER_IDENTIFIERStringUnique Id to Register the User
APNS_DEVICE_TOKENStringToken to register APNS device (optional)
VOIP_DEVICE_TOKENStringToken to register VoIP device (optional)
IS_EXPORTBooltrue for production(apns certificate) builds and false for sandbox(apns certificate)builds
IS_FORCE_REGISTERBooldefault value true provide true to force the logout of the old session If the registered user has reached the maximum no of multi-sessions or provide false to allow registration till the maximum no of multi-sessions
USER_TYPEStringType of the user (optional)
META_DATA[MetaData]list of key - value pair of metadata object. Maximum size is 3 (optional)
CALLBACKFlyCompletionHandlerFlyCompletionHandler is implemented and expressed as lambda expression
PUSHSERVERTYPEPushServerTypeEnumPUSHSERVERTYPE to receive push notification via apns or firebase

To know more about FlyCompletionHandler click here


If IS_FORCE_REGISTER is false, and it reached the maximum no of multi-sessions then registration will not succeed it will throw a 405 exception, Either IS_FORCE_REGISTER should be true or one of the existing session need to be logged out to continue registration.


Save your own contact details in DB after registration. Your contact detail will be used while sending group messages. Call below method to save your own contact details,

let userProfile: ProfileDetails = ContactManager.shared.saveTempContact(userId: "OUR OWN JID" , name: "OUR NAME")

To generate a unique user id, you must pass the username in the method let userJID: String = try FlyUtils.getJid(USERNAME)

Connect to the Chat Server#

Once Registration was successful, ChatSDK automatically attempts to connect to the Chat Server and ChatSDK also observe the changes in application state, and accordingly it will try to connect and disconnect the Chat Server.

Observe Connection Events#

The connection status can be observed and tracked by confirming the ConnectionEventDelegate. To do that you need to set ‘delegate’ in your ViewController's viewDidAppear method like below.

ChatManager.shared.connectionDelegate = self

Once the ConnectionEventDelegate has been set, you will be able to receive the connection status in the delegate method as mentioned below.

func onConnected() {
// Navigate to Conversation screen

To know more about ConnectionEventDelegate visit ConnectionEvent Delegate


The below given are some of the common keyword/terminologies used in the Chat SDK with description

userID/userBareIDUnique 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: https://xmpp.org/extensions/xep-0106.html
userJid (or) JIDuserID+@+domain of the chat server Ex. 12345678@xmpp.chatsystem.dev.contus.us
groupID/groupBareIDUnique ID assigned for each group Ex: group123456 (any alphanumeric). GroupJID = groupID +@mix.+domain of the chat server Ex: group123456@mix.xmpp.mirrorfly.dev.contus.us`

SDK here provides the built-in functions to prepare the JID and Group JID.

Send a One-to-One Message#

The below method is used to send a text message from one user to another.

Note: To generate a unique user id, you must call the other user's username in the method String userJID = FlyUtils.getJid(USERNAME)

FlyMessenger.sendTextMessage(TO_JID, TEXT) { isSuccess,error,chatMessage in
if isSuccess {
// Update the UI
// Handle the error
TO_JIDStringjid of the end user
TEXTStringSpecifies the text message that needs to be sent
REPLY_MESSAGE_IDStringProvides the Message ID of replied message or else generates an empty string (optional)
CALLBACKSendMessageListenercallback to observe the action status

Receive a One-to-One Message#

Set the delegate in your ViewController's viewDidAppear method using below syntax and confirm the MessageEventsDelegate class, this will enable you to see other incoming messages and related events.

ChatManager.shared.messageEventsDelegate = self

Once the delegate has been set, we will be able to receive the incoming message in the method mentioned below.To know more about other methods in MessageEventsDelegate.

func onMessageReceived(message: ChatMessage, chatJid: String) {
// Message received from chatJid, content is message.messageTextContent

Note: MessageEventsDelegate protocol has 12 delegate methods onMessageReceived is one of them. Kindly visit MessageEvent Delegate to know more about them.