Skip to content

Vishal-D4/DemoApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YourGPT Widget SDK Integration Guide

This guide walks you through integrating the YourGPT Widget SDK into your iOS SwiftUI application.

Prerequisites

  • Xcode 14.0 or later
  • iOS 15.0 or later
  • Swift 5.7 or later
  • A YourGPT Widget UID (get one from YourGPT Dashboard)

Installation

Step 1: Add the SDK Package Dependency

  1. Open your Xcode project
  2. Go to File → Add Package Dependencies...
  3. Enter the repository URL:
    https://github.com/YourGPT/yourgpt-widget-sdk-ios.git
    
  4. Select Branch: main as the dependency rule
  5. Click Add Package
  6. Ensure YourGPTSDK is added to your target
  7. Click Add Package again to confirm

Step 2: Import the SDK

In any Swift file where you want to use the SDK, import it:

import YourGPTSDK

Integration

Step 3: Create a SwiftUI Wrapper (Recommended)

Create 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
    }
}

Step 4: Use the Widget in Your Views

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")
            }
        }
    }
}

Step 5: Configure Your Widget UID

Replace "YOUR_WIDGET_UID_HERE" with your actual Widget UID from the YourGPT dashboard.

Example:

YourGPTWrapper(widgetUid: "69dd8b5d-d4bf-444c-a40f-732d15248ae9")

Implementation Options

Option A: Sheet Presentation (Recommended)

.sheet(isPresented: $showSupportChat) {
    YourGPTWrapper(widgetUid: "YOUR_WIDGET_UID_HERE")
}

Option B: Full Screen Cover

.fullScreenCover(isPresented: $showSupportChat) {
    YourGPTWrapper(widgetUid: "YOUR_WIDGET_UID_HERE")
}

Option C: Navigation Link

NavigationLink("Support") {
    YourGPTWrapper(widgetUid: "YOUR_WIDGET_UID_HERE")
}

Common Use Cases

Adding to Toolbar

.toolbar {
    ToolbarItem(placement: .navigationBarLeading) {
        Button("Support") {
            showSupportChat = true
        }
    }
}

Floating Button

.overlay(alignment: .bottomTrailing) {
    Button {
        showSupportChat = true
    } label: {
        Image(systemName: "message.circle.fill")
            .font(.system(size: 50))
            .foregroundColor(.blue)
            .padding()
    }
}

Verification

  1. Build and run your app (Cmd + R)
  2. Tap the button/trigger to open the widget
  3. The YourGPT chatbot interface should appear
  4. Test the chat functionality

Troubleshooting

Build Errors

  • Ensure the package dependency is properly added
  • Clean build folder: Product → Clean Build Folder (Cmd + Shift + K)
  • Restart Xcode if needed

Widget Not Displaying

  • Verify your Widget UID is correct
  • Check that you've imported YourGPTSDK in the file
  • Ensure iOS deployment target is 15.0 or later

Runtime Issues

  • Check console logs for any error messages
  • Verify internet connectivity (required for the widget to function)

Example Project Structure

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

Resources

Support

For questions or issues:

  • Visit the YourGPT support page
  • Check the SDK repository issues
  • Contact YourGPT support team

License

This SDK is provided by YourGPT. Check the SDK repository for license information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages