Skip to content

Commit f6ffbf9

Browse files
authored
feat: UIKit migration
1 parent 13564bc commit f6ffbf9

File tree

4 files changed

+558
-621
lines changed

4 files changed

+558
-621
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PackageDescription
66
let package = Package(
77
name: "ChatwootSDK",
88
platforms: [
9-
.iOS(.v14)
9+
.iOS(.v12)
1010
],
1111
products: [
1212
// Products define the executables and libraries a package produces, making them visible to other packages.

README.md

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
1-
# 💬 Chatwoot iOS SDK (SwiftUI)
1+
# 💬 Chatwoot Agent iOS SDK (UIKit)
22

3-
iOS SDK for Chatwoot
3+
A lightweight iOS SDK built with **Swift** and **UIKit** to embed a Chatwoot-powered chat interface in any iOS app.
44

55

66

7-
## 📦 Installation
7+
## 🎯 Objective
88

9-
### Option 1: Swift Package Manager (Recommended)
9+
- Enable any iOS app to launch a full-featured Chatwoot chat screen
10+
- Use UIKit for broad iOS compatibility (iOS 12+)
1011

11-
You can integrate the Chatwoot iOS SDK using Swift Package Manager:
12+
## 🧱 Supported Platforms
1213

13-
1. Open your Xcode project.
14-
2. Navigate to `File > Add Packages...`
15-
3. Enter the following URL in the search field:
16-
```
17-
https://github.com/chatwoot/agent-ios-sdk.git
18-
```
19-
4. Select the version you want to use (e.g. from version `1.0.0`) and click **Add Package**.
14+
-**Swift 5.7+**
15+
-**UIKit Framework**
16+
-**iOS 12+** (Broad device compatibility)
17+
-**SwiftUI Compatible** (via UIViewControllerRepresentable)
2018

21-
Then, import the SDK in your code:
22-
```swift
23-
import ChatwootSDK
24-
```
2519

26-
### Option 2: Manual via `Package.swift`
2720

28-
If you're managing dependencies directly with Swift Package Manager via `Package.swift`:
21+
## 📦 Installation
22+
23+
### **Via Swift Package Manager (Remote)**
24+
25+
In `Package.swift`:
2926

3027
```swift
31-
.package(url: "https://github.com/chatwoot/agent-ios-sdk.git", from: "1.0.0")
28+
.package(url: "https://github.com/chatwoot/ios-agent-sdk", from: "1.0.0")
3229
```
3330

34-
Then, import the SDK where needed:
31+
### **Via Xcode (Local Package)**
32+
33+
1. **Open your Xcode project**
34+
2. **Add Package Dependency:**
35+
- Go to **File → Add Package Dependencies...**
36+
- Click **Add Local..** (bottom left)
37+
- Navigate to your local `ios-sdk` folder
38+
- Select the folder and click **Add Package**
39+
3. **Configure Package:** Select your target(s) and click **Add Package**
40+
41+
### **Import in your app:**
42+
3543
```swift
3644
import ChatwootSDK
3745
```
@@ -62,43 +70,63 @@ To enable photo capture or image upload features in the chat interface, **you mu
6270
## ⚙️ Configuration Parameters
6371

6472
| Parameter | Type | Required | Description |
65-
|-----------------|-----------|----------|---------------------------------------------|
73+
|--|-----------|----------|---------------------------------------------|
6674
| `accountId` | `Int` || Unique ID for the Chatwoot account |
6775
| `apiHost` | `String` || Chatwoot API host URL |
6876
| `accessToken` | `String` || Access token for authentication |
6977
| `pubsubToken` | `String` || Token for real-time updates |
7078
| `websocketUrl` | `String` || WebSocket URL for real-time communication |
7179

80+
---
7281

7382
## 🛠️ Example Usage
7483

75-
### Step 1: Set up the SDK
84+
### UIKit
7685

7786
```swift
87+
import ChatwootSDK
88+
89+
// 1. Setup in AppDelegate/SceneDelegate
7890
ChatwootSDK.setup(ChatwootConfiguration(
7991
accountId: 1,
8092
apiHost: "https://your-chatwoot.com",
8193
accessToken: "YOUR_ACCESS_TOKEN",
8294
pubsubToken: "YOUR_PUBSUB_TOKEN",
8395
websocketUrl: "wss://your-chatwoot.com"
8496
))
97+
98+
// 2. Present chat modally
99+
ChatwootSDK.presentChat(from: self, conversationId: 123)
85100
```
86101

87-
### Step 2: Show the Chat Interface
102+
### SwiftUI
88103

89104
```swift
90-
@State private var showChat = false
91-
@State private var conversationId: Int = 123 // Required: conversation ID to load
105+
import SwiftUI
106+
import ChatwootSDK
92107

93-
var body: some View {
94-
Button("Open Chat") {
95-
showChat = true
108+
struct ChatwootWrapper: UIViewControllerRepresentable {
109+
let conversationId: Int
110+
111+
func makeUIViewController(context: Context) -> UIViewController {
112+
return ChatwootSDK.loadChatUI(conversationId: conversationId)
96113
}
97-
.fullScreenCover(isPresented: $showChat) {
98-
ChatwootSDK.loadChatUI(conversationId: conversationId)
114+
115+
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
116+
}
117+
118+
struct ContentView: View {
119+
@State private var showChat = false
120+
121+
var body: some View {
122+
Button("Open Chat") {
123+
showChat = true
124+
}
125+
.fullScreenCover(isPresented: $showChat) {
126+
ChatwootWrapper(conversationId: 123)
127+
}
99128
}
100129
}
101130
```
102131

103-
The `conversationId` is required to load the chat UI. Make sure you have a valid conversation ID before calling `loadChatUI`.
104-
132+
The conversationId is required to load the chat UI. Make sure you have a valid conversation ID before calling loadChatUI.

0 commit comments

Comments
 (0)