iOS Usage
The Lovina Chat SDK provides LovinaChatWidget (a UIView subclass) for UIKit and LovinaChatView (a UIViewRepresentable) for SwiftUI.
UIKit Integration
import UIKit
import LovinaChatSDK
class ChatViewController: UIViewController {
private let chatWidget = LovinaChatWidget()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(chatWidget)
chatWidget.frame = view.bounds
chatWidget.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Listen for events
chatWidget.onEvent = { event in
switch event {
case .loaded(let authToken):
print("Widget loaded, token: \(authToken ?? "none")")
case .messageReceived(let message):
print("New message: \(message)")
case .unreadCountChanged(let count):
self.updateBadge(count)
case .closed:
self.dismiss(animated: true)
case .error(let code, let message):
print("Error [\(code)]: \(message)")
}
}
// Configure and load
chatWidget.configure(LovinaChatConfig(
websiteToken: "your-website-token",
baseUrl: "https://chat-prod.ailovina.com"
))
}
deinit {
chatWidget.destroy()
}
}
SwiftUI Integration
Use the LovinaChatView wrapper to embed the chat widget in SwiftUI:
import SwiftUI
import LovinaChatSDK
struct ChatScreen: View {
var body: some View {
LovinaChatView(
config: LovinaChatConfig(
websiteToken: "your-website-token",
baseUrl: "https://chat-prod.ailovina.com"
),
onEvent: { event in
switch event {
case .messageReceived(let message):
print("New message: \(message)")
default:
break
}
}
)
.edgesIgnoringSafeArea(.all)
}
}
User Identification
Pass user information to associate messages with a known contact:
let config = LovinaChatConfig(
websiteToken: "your-token",
baseUrl: "https://chat-prod.ailovina.com",
user: LovinaChatUser(
identifier: "user-12345",
name: "Jane Doe",
email: "jane@example.com",
identifierHash: "hmac-hash-for-verification",
phoneNumber: "+6281234567890",
customAttributes: [
"plan": "premium",
"signup_date": "2025-01-15"
]
)
)
Theming and White-Label Branding
Customize colors, typography, and branding via theme and branding. Theme colors are hex strings, not UIColor:
let config = LovinaChatConfig(
websiteToken: "your-token",
baseUrl: "https://chat-prod.ailovina.com",
theme: LovinaThemeConfig(
primaryColor: "#6366F1" // Indigo
),
branding: LovinaBrandingConfig(
brandName: "Acme Support",
poweredBy: false
)
)
See Configuration for the full set of theme, branding, texts, and features options.
Session Management
Conversation sessions are persisted automatically in the Keychain. Returning users resume their existing conversation.
To clear a session and start fresh:
chatWidget.clearSession()
chatWidget.reload()
Lifecycle
The widget cleans up automatically in deinit. You may also call destroy() explicitly when the hosting view controller is dismissed:
deinit {
chatWidget.destroy()
}