Initialization

Licensing#

ChatSDK must be authenticated with the backend server using the License key obtained from the console. Write the license key to ChatSDK by calling the below method in the didFinishLaunchingWithOptions method of AppDelegate. But only after setting the app group id using the method FlyUtils.setAppGroupContainerId(id: CONTAINER_ID ).

FlyDefaults.licenseKey = LICENSE_KEY

Privacy and Security law compliance#

An SDK must be in compliance to multiple privacy and security laws across the major nations to distribute the application in those countries. As of now our ChatSDK is in compliance to GDPR, for that personal sensitive information has to encrypted. We need to provide an IV for those encryption and decryption process.

FlyDefaults.profileIV = PROFILE_IV
caution

Profile IV must be a string of length 16, orelse encryption/decryption will fail.

Initialize ChatSDK#

To start using the sdk, there were few data that were required by the SDK for initialization. For which we use the ChatSDK builder class. In your AppDelegate class , under 'didFinishLaunchingWithOptions' use the below method to pass those required data to the SDK . An example can be found below.

let groupConfig = try? GroupConfig.Builder
.enableGroupCreation(groupCreation: true)
.onlyAdminCanAddOrRemoveMembers(adminOnly: true)
.setMaximumMembersInAGroup(membersCount: 200)
.build()
ChatSDK.Builder.enableContactSync(isEnable: true)
.setDomainBaseUrl(baseUrl: "https://www.contus.com/chat/api/v1/")
.setMaximumPinningForRecentChat(maxPinChat: 4)
.setGroupConfiguration(groupConfig: groupConfig!)
.deleteMediaFromDevice(delete: true)
.setAppGroupContainerID(containerID: "group.com.contus")
.buildAndInitialize()

Chat Builder Function Description#

FunctionParameter TypeDescription
enableContactSyncBoolif set true syncing of phone book contacts will be enabled
setDomainBaseUrlStringurl needed for api calls provided by Chat team
setMaximumPinningForRecentChatIntmaximum pin count in recent chat
setGroupConfigurationGroupConfigconfiguration for the group implementation
deleteMediaFromDevicebooleanTo show whether contact's profile name or nickname from sdk
setAppGroupContainerIDStringPass group container id of the project to store UserDefaults and Database
buildAndInitializen/ainitialize the chat configuration

GroupConfig Builder Function Description#

FunctionArgument TypeDescription
enableGroupCreationbooleanenable/disable group creation
setMaximumMembersInAGroupintset the maximum number of members a group can have(cannot be greater than 300)
onlyAdminCanAddOrRemoveMembersbooleanif true only group admin can add/remove members else members can add/remove other members
buildn/abuild GroupConfig object
caution

Base url must have http/https protocol and should end with / else an exception will be thrown.

Push Notifications#

To receive messages in the background or in the killed state, kindly register for remote notification by conforming to the following delegates in the AppDelegate UNUserNotificationCenterDelegate. Call the below methods when an APNS token gets updated.

// APNS Token Update
VOIPManager.sharedInstance.saveAPNSToken(token: token)
VOIPManager.sharedInstance.updateDeviceToken()
ArgumentDescription
TOKENApns Token

App Group Id#

In order to access data between app and notification extension, enabling app group is mandatory, and a group container id is necessary for Chat sdk to function properly.

FlyUtils.setAppGroupContainerId(id: "APP_GROUP_ID")
ArgumentDescription
APP_GROUP_IDId of the application App group
info

Sets the group container id in AppDelegate's didFinishLaunchingWithOptions method and in the didReceive methods of the class that extends UNNotificationServiceExtension before calling any other Call SDK methods even before the Call SDK Builder method.

App Capabilities#

Chat SDK also requires the application to enable the below capabilities to function seamlessly without any issues.

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

Registration#

To register a new user use the below method. This method will take care sandbox mode registration or live mode registration based on FlyDefaults.isTrialLicense value provided. Kindly set FlyDefaults.isTrialLicenseto false to point to dedicated server or else to test on trial server.

ArgumentTypeDescription
UNIQUE_IDENTIFIERStringunique id of the user
APNS_TOKENStringAPNS token generated by the app
VOIP_TOKENStringVOIP token generated by the app
IS_LIVEBoolwhile exporting set it to true else false.
ChatManager.registerApiService(for: UNIQUE_IDENTIFIER, deviceToken: APNS_TOKEN, voipDeviceToken: VOIP_TOKEN, isLive: IS_LIVE) { isSuccess, flyError, flyData in
if isSuccess {
completionHandler(data, nil)
}else{
let error = data.getMessage()
completionHandler(data, error as? String)
}
}

Connect to the chat server#

In order to send messages using the chat sdk , at first you need to establish the connection to the server. sdk provides methods for initializing the connection configuration as well as methods for making connection.

At first initialize the connection details using the below method. This method will store the connection details in persistent storage to make connection automatically once you close and reopen the app.

ArgumentTypeDescription
USERNAMEStringuserName for making connection to the server
SECRET_KEYStringpassword used to authenticate to the xmpp server
XMPP_DOMAINStringdomain name which will be used in jid
XMPP_HOSTStringxmpp server url
XMPP_PORTintport of the xmpp server
ChatManager.shared.initialize(username: USERNAME, secretKey:SECRET_KEY, xmppDomain: XMPP_DOMAIN, xmppPort: XMPP_PORT)

Once you initialized the connection details, for the first time you need to call the below method to make connection to the chat server immediately after that you don't need to call this method anymore, sdk will handle connection and disconnection on behalf of you.

ChatManager.makeXMPPConnection()

Set IV and Token#

Once register is successful call the below method and pass the IV and auth token to SDK.

ChatManager.setIV(IV)
ChatManager.setAuthToken(TOKEN);
ArgumentTypeDescription
IVStringInitialization vector for data encryption and decryption
TOKENStringAuth token received during registration for making api calls