This guide walks you through integrating the YourGPT Widget SDK into your iOS SwiftUI application.
- Xcode 14.0 or later
- iOS 15.0 or later
- Swift 5.7 or later
- A YourGPT Widget UID (get one from YourGPT Dashboard)
- Open your Xcode project
- Go to File → Add Package Dependencies...
- Enter the repository URL:
https://github.com/YourGPT/yourgpt-widget-sdk-ios.git - Select Branch: main as the dependency rule
- Click Add Package
- Ensure YourGPTSDK is added to your target
- Click Add Package again to confirm
In any Swift file where you want to use the SDK, import it:
import YourGPTSDKCreate a new Swift file named YourGPTWrapper.swift:
import SwiftUI
import YourGPTSDK
struct YourGPTWrapper: UIViewControllerRepresentable {
@Environment(\.presentationMode) var presentationMode
let widgetUid: String
func makeUIViewController(context: Context) -> UIViewController {
let chatbotVC = YourGPTSDK.createChatbotViewController(widgetUid: widgetUid)
return chatbotVC
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
// No updates needed
}
}Add the widget to your SwiftUI view using a sheet or fullScreenCover:
import SwiftUI
import YourGPTSDK
struct ContentView: View {
@State private var showSupportChat: Bool = false
var body: some View {
NavigationStack {
VStack {
// Your app content here
Button("Open Support Chat") {
showSupportChat = true
}
}
.navigationTitle("My App")
.sheet(isPresented: $showSupportChat) {
YourGPTWrapper(widgetUid: "YOUR_WIDGET_UID_HERE")
}
}
}
}Replace "YOUR_WIDGET_UID_HERE" with your actual Widget UID from the YourGPT dashboard.
Example:
YourGPTWrapper(widgetUid: "69dd8b5d-d4bf-444c-a40f-732d15248ae9").sheet(isPresented: $showSupportChat) {
YourGPTWrapper(widgetUid: "YOUR_WIDGET_UID_HERE")
}.fullScreenCover(isPresented: $showSupportChat) {
YourGPTWrapper(widgetUid: "YOUR_WIDGET_UID_HERE")
}NavigationLink("Support") {
YourGPTWrapper(widgetUid: "YOUR_WIDGET_UID_HERE")
}.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Support") {
showSupportChat = true
}
}
}.overlay(alignment: .bottomTrailing) {
Button {
showSupportChat = true
} label: {
Image(systemName: "message.circle.fill")
.font(.system(size: 50))
.foregroundColor(.blue)
.padding()
}
}- Build and run your app (Cmd + R)
- Tap the button/trigger to open the widget
- The YourGPT chatbot interface should appear
- Test the chat functionality
- Ensure the package dependency is properly added
- Clean build folder: Product → Clean Build Folder (Cmd + Shift + K)
- Restart Xcode if needed
- Verify your Widget UID is correct
- Check that you've imported
YourGPTSDKin the file - Ensure iOS deployment target is 15.0 or later
- Check console logs for any error messages
- Verify internet connectivity (required for the widget to function)
DemoApp/
├── DemoApp/
│ ├── DemoAppApp.swift # App entry point
│ ├── ContentView.swift # Main view with widget integration
│ ├── YourGPTWrapper.swift # SwiftUI wrapper for the SDK
│ └── [Other app files]
├── DemoApp.xcodeproj
└── README.md
- YourGPT Dashboard: https://yourgpt.ai
- SDK Repository: https://github.com/YourGPT/yourgpt-widget-sdk-ios
- Documentation: https://docs.yourgpt.ai
For questions or issues:
- Visit the YourGPT support page
- Check the SDK repository issues
- Contact YourGPT support team
This SDK is provided by YourGPT. Check the SDK repository for license information.