Live Chat SDK Swift
Configuration
Untuk dapat menggunakan SDK connector ini, perlu untuk mencapai persyaratan berikut:
XCode 10.0+ (rekomendasi menggunakan XCode 12.1+)
Swift 4.0, 4.1, 4.2, 5.0
Installation
Berikut merupakan cara untuk melakukan instalasi menggunakan framework tersebut:
Dapatkan file
imi_dolphin_livechat_ios_xcframework
Buka Xcode project Anda dan masuk ke Project Settings > General
Pada bagian bawah Framework, Libraries, dan Embedded Content, klik tombol '+' dan pilih Add Other... > Add Files..
Tempatkan dan tambahkan
imi_dolphin_livechat_ios_xcframework
pada project Anda.Pastikan bahwa Embed & Sign sudah dipilih untuk menggabungkan framework dengan aplikasi Anda dengan benar
Ulangi langkah yang sama untuk menambahkan dependensi seperti
StompClientLib
danCryptoSwift.xcframework
jika dibutuhkan
Import Library
Tambahkan script import berikut di bagian atas file Swift Anda:
import imi_dolphin_livechat_ios
Initialize User Profile
Buat profile user menggunakan kelas dari DolphinProfile
:
let dolphinProfile = DolphinProfile(
name: nameTextField.text!,
email: emailTextField.text!,
phoneNumber: phoneTextField.text!,
customerId: "",
uid: ""
)
Penjelasan Komponen:
DolphinProfile
Merupakan identitas dari user yang melakukan chat
name
Merupakan nama dari user tersebut
Merupakan email dari user tersebut
phoneNumber
Merupakan nomor teleponn dari user tersebut
uid
Berguna untuk menentukan sesi user ini akan membuat tiket baru atau tidak
Initialize Connection Variables
Tentukan notification listener dan variabel yang dibutuhkan:
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
Pastikan gambar memenuhi persyaratan berikut:
Ukuran gambar dibawah 2MB
Memiliki format PNG atau JPEG
connector!.sendAttachment(fileNsUrl: "IMAGE_FILEPATH", state: state!, dataUser: sample)
Send Video
Pastikan video memenuhi persyaratan berikut:
Ukuran video dibawah 2MB
Memiliki format MP4
connector!.sendAttachment(fileNsUrl: "VIDEO_FILEPATH", state: state!, dataUser: sample)
Send File (Document and Audio as File)
Ukuran Dokumen/Audio dibawah 2MB
Memiliki format PDF
connector?.sendAttachment(fileNsUrl: AUDIO/DOCUMENT_FILEPATH as NSURL, state: state!, dataUser: sample)
Last updated
Was this helpful?