Live Chat SDK Swift

Configuration

To use this SDK connector, you must meet the following requirements:

  • XCode 10.0+ (recommended to use XCode 12.1+)

  • Swift 4.0, 4.1, 4.2, 5.0

Installation

Recommended to use framework from .xcframework.

Steps to install using this framework:

  1. Obtain file imi_dolphin_livechat_ios_xcframework

  2. Open your Xcode project and navigate to Project Settings > General

  3. Under Framework, Libraries, and Embedded Content, click button '+' and select Add Other... > Add Files..

  4. Locate and add imi_dolphin_livechat_ios_xcframework to your project

  5. Ensure that Embed & Sign is selected to properly bundle the framework with your app

  6. Repeat the same steps to add any dependencies like StompClientLib dan CryptoSwift.xcframework if needed

Import Library

Add the following import statement at the top of your Swift file:

import imi_dolphin_livechat_ios

Initialize User Profile

Create a user profile using the classDolphinProfile :

let dolphinProfile = DolphinProfile(
name: nameTextField.text!,
email: emailTextField.text!,
phoneNumber: phoneTextField.text!,
customerId: "",
uid: ""
)

Component Explanation:

Name
Description

DolphinProfile

Represents the identify of the user initiating the chat

name

Represents the name of the user

email

Represents the user's email

phoneNumber

Represents the user's phone number

uid

Used to determine whether this user session will create a new ticket or not

Initialize Connection Variables

Define the required notification listeners and connection variables:

var connector: Connector?
let notificationMessage = "com.connector.notificationMessage"
let notificationConnectionStatus = "com.connector.connectionStatus"
let notificationReadMessage = "com.connector.notificationReadMessage"
let notificationTypingCondition = "com.connector.notificationTypingCondition"

Setup Connection in viewDidLoad

connector!.setupConnection(baseUrl: baseUrl, clientId: clientId, clientSecrect: clientSecrect)
connector?.enableGetQueue(isEnable: false)
connector!.constructConnector(profile: dolphinProfile!)

NotificationCenter.default.addObserver(self, selector: #selector(doOnReceiveMessage(_:)), name: Notification.Name(rawValue: notificationMessage), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(doUpdateConnectionStatus(_:)), name: Notification.Name(rawValue: notificationConnectionStatus), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(doUpdateStatusMessage(_:)), name: Notification.Name(rawValue: notificationReadMessage), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(doUpdateTypingCondition(_:)), name: Notification.Name(rawValue: notificationTypingCondition), object: nil)

Implement Notification Handlers

@objc func doOnReceiveMessage(_ notification: NSNotification) {
let newMessage = notification.object as! DolphinMessage
// Handle received message
}
@objc func doUpdateConnectionStatus(_ notification: NSNotification) {
let status: Int = notification.object as! Int
// Handle connection status updates
}
@objc func doUpdateStatusMessage(_ notification: NSNotification){
let updatedMessage = notification.object as! DolphinMessage
// Handle message status updates
}
@objc func doUpdateTypingCondition(_ notification: NSNotification){
// Handle typing condition updates
}

Sending Messages

Send Text Message

connector?.onSendMessage(messages: "TEXT_MESSAGE_STRING", dataUser: sample)

Send Image

Ensure image file meets these conditions:

  • Image size must be under 2MB

  • Using format PNG or JPEG

connector!.sendAttachment(fileNsUrl: "IMAGE_FILEPATH", state: state!, dataUser: sample)

Send Video

Ensure video file meets these conditions:

  • Video size must be under 2MB

  • Using format MP4

connector!.sendAttachment(fileNsUrl: "VIDEO_FILEPATH", state: state!, dataUser: sample)

Send File (Document and Audio as File)

Ensure documents file meets these conditions:

  • Document/Audio size must be under 2MB

  • Memiliki format PDF

connector?.sendAttachment(fileNsUrl: AUDIO/DOCUMENT_FILEPATH as NSURL, state: state!, dataUser: sampl

Last updated

Was this helpful?