Updated on July 13, 2026

TL;DR: Integrating Kommunicate into a SwiftUI app takes about 11 steps, but the core process is straightforward.

  1. Install the Kommunicate iOS SDK using CocoaPods or Swift Package Manager, add an AppDelegate, and connect it to your SwiftUI app using UIApplicationDelegateAdaptor.
  2. Add a top-view-controller helper so Kommunicate can present its interface, then connect a Contact Support button to Kommunicate.createAndShowConversation.
  3. Register logged-in users with a stable user ID and pass metadata such as their plan, current screen, or order ID before opening the conversation. This gives the AI agent context from the first message.
  4. Use KMConversationBuilder when you need to route conversations to a specific AI agent, assign them to a support team, or pass screen-level metadata.
  5. Configure push notifications so users can return to open conversations after leaving the app, while keeping human escalation available when needed.

Adding support to an iOS app should not force users to leave the product, search for an email address, or wait for a human agent to reply. The stakes are real: a Helpshift survey found that 66% of mobile users feel extremely or very frustrated when they need in-app help but get kicked out of the app or face a long wait, and 71% said they would switch to a competing product after a bad in-app support experience.

That is where a SwiftUI chatbot integration can help.

With Kommunicate, you can add an AI-powered support chatbot to your iOS app, giving users a way to: 

  • Ask questions
  • Get instant answers
  • Share context
  • Escalate to a human support agent

The chatbot handles repetitive support queries, while your team stays available for cases that need human judgment.

In this guide, we will walk through how to integrate Kommunicate into a SwiftUI app, initialize the SDK, register users, and launch an AI support conversation from inside the app. We’ll cover:

  1. What Are We Building?
  2. Prerequisites
  3. How to create a Kommunicate AI agent?
  4. How to Integrate Kommunicate Into a SwiftUI App?
  5. Best Practices for SwiftUI Chatbot Integration
  6. Testing Checklist
  7. Common Integration Issues
  8. Conclusion

What Are We Building?

We are building a simple SwiftUI support flow where a user can tap a Contact Support button and open an in-app AI support conversation.

The setup includes:

  • Installing the Kommunicate iOS SDK
  • Adding required iOS permissions
  • Creating an AppDelegate for SDK initialization
  • Connecting that AppDelegate to a SwiftUI app
  • Launching the chatbot from a SwiftUI screen
  • Registering logged-in users
  • Passing metadata for better support context
  • Optionally routing conversations to a specific AI agent or support team

By the end, your SwiftUI app will be ready to launch an in-app support chatbot backed by Kommunicate.

Prerequisites

Before starting, make sure you have:

  • A SwiftUI iOS app
  • Xcode installed
  • A Kommunicate account
  • Your Kommunicate App ID (You will need to sign up for Kommunicate)
  • CocoaPods or Swift Package Manager access

You can find your Kommunicate App ID in the Kommunicate dashboard. This App ID is required to initialize the SDK inside your iOS app.

How to create a Kommunicate AI agent?

Before you connect Kommunicate to your SwiftUI app, create the AI agent that will respond to users inside the chat. We have a detailed video guide explaining how to do this:

Here’s a brief overview of how to create one:

  1. Log in to your Kommunicate dashboard and go to Agent Integrations. From there, create a new AI agent and choose how you want it to answer customer questions. You can train the agent using your website URLs, help center articles, FAQs, PDFs, or other support documents.
  2. Once the knowledge sources are added, test the agent from the dashboard before adding it to your iOS app. Ask common customer questions, check whether the answers are accurate, and confirm that the agent knows when to hand over the conversation to a human support team.
  3. For a SwiftUI app, it is useful to create agents around specific support use cases. For example, you can create one AI agent for account support, another for order-related questions, and another for billing or subscription issues. Later in the integration, you can use the agent ID inside KMConversationBuilder to route users to the right AI agent based on where they open the chat.

After the AI agent is ready, copy the APP ID from the Kommunicate dashboard. You will use this ID when creating a custom conversation flow in your SwiftUI app.

How to integrate Kommunicate into a SwiftUI app?

Step 1: Install the Kommunicate iOS SDK

Kommunicate supports iOS SDK installation through CocoaPods and Swift Package Manager.

Option 1: Install with CocoaPods

Open your Podfile and add Kommunicate:

pod ‘Kommunicate’, ‘~> 7.1.9’

Then run:

pod install

After installation, open the .xcworkspace file instead of the .xcodeproj file. This avoids the common no such module error after installing dependencies through CocoaPods.

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

import Kommunicate

Option 2: Install with Swift Package Manager

In Xcode:

File > Add Package Dependencies

Add the Kommunicate iOS SDK package from the repository and wait for Xcode to resolve the dependency.

Step 2: Add the required iOS permissions

If your support chatbot allows users to send images, take photos, record audio, or share location, your app needs the required iOS permission descriptions.

Open your app’s Info.plist as source code and add the following keys inside the <dict> tag:

<key>NSCameraUsageDescription</key>
<string>Allow Camera</string>

<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow location sharing</string>

<key>NSMicrophoneUsageDescription</key>
<string>Allow Microphone</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>Allow Photos</string>

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Allow write access</string>

Step 3: Create an AppDelegate for SwiftUI

SwiftUI apps do not include an AppDelegate by default. SDK setup tasks, push notification handling, and global configuration are handled through one.

Create a new Swift file named: AppDelegate.swift

Add the following code:

import UIKit
import Kommunicate

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        Kommunicate.setup(applicationId: “YOUR_APP_ID”)
        return true
    }
}

Replace YOUR_APP_ID with your Kommunicate App ID.

Step 4: Register AppDelegate in your SwiftUI app

Connect the AppDelegate to your SwiftUI app using UIApplicationDelegateAdaptor.

Open your main app file and update it with:

import SwiftUI

@main
struct SupportChatApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
       WindowGroup {
           ContentView()
        }
    }
}

This lets you keep the SwiftUI app lifecycle while still using UIKit-style setup where needed.

Step 5: Create a top view controller helper

Kommunicate presents the conversation screen from a UIViewController. In SwiftUI, you do not have direct access to self as a UIViewController, so add a helper extension that finds the topmost view controller in the current app window.

Create a new Swift file: UIApplication+TopViewController.swift.

Add this extension:

import UIKit

extension UIApplication {
    static func topViewController(
        base: UIViewController? = UIApplication.shared.connectedScenes
            .compactMap { $0 as? UIWindowScene }
            .flatMap { $0.windows }
            .first(where: { $0.isKeyWindow })?
            .rootViewController
    ) -> UIViewController? {
        if let navigationController = base as? UINavigationController {
            return topViewController(base: navigationController.visibleViewController)
        }

        if let tabBarController = base as? UITabBarController,
          let selectedViewController = tabBarController.selectedViewController {
            return topViewController(base: selectedViewController)
        }

        if let presentedViewController = base?.presentedViewController {
            return topViewController(base: presentedViewController)
        }

        return base
    }
}

Step 6: Launch the AI chatbot from a SwiftUI Button

Add a support button inside your SwiftUI view:

import SwiftUI
import Kommunicate

struct ContentView: View {
    var body: some View {
        VStack(spacing: 20) {
            Text(“Need help?”)
                .font(.title)

            Button(“Contact Support”) {
                openSupportChat()
            }
            .buttonStyle(.borderedProminent)
        }
        .padding()
    }

    private func openSupportChat() {
        guard let topViewController = UIApplication.topViewController() else {
            print(“Could not find top view controller”)
            return
        }

        Kommunicate.createAndShowConversation(from: topViewController) { error in
            if let error = error {
                print(“Conversation error: \(error.localizedDescription)”)
                return
            }

            print(“Conversation opened successfully”)
        }
    }
}

When the user taps Contact Support, Kommunicate opens the conversation screen. If no conversation exists, a new one is created. If an existing conversation is available, it reopens. If multiple conversations exist, the user sees the conversation list.

Step 7: Register logged-in users

For a production app, identify users before launching support. This helps your support team see who the user is and maintain conversation continuity across sessions.

import Kommunicate

func registerKommunicateUser(
    userId: String,
    name: String,
    email: String
) {
    if Kommunicate.isLoggedIn {
        return
    }

    let kmUser = KMUser()
    kmUser.userId = userId
    kmUser.applicationId = “YOUR_APP_ID”
    kmUser.displayName = name
    kmUser.email = email

    Kommunicate.registerUser(kmUser) { response, error in
        if let error = error {
            print(“User registration failed: \(error.localizedDescription)”)
            return
        }

        print(“User registered successfully”)
    }
}

Call this after the user logs in to your app. Use a stable, unique user ID from your own system. Generating a new random user ID for the same user each session will split the conversation history.

Step 8: Pass user metadata for better support context

You can pass metadata to Kommunicate, so your AI agent or human support team understand the user’s context before the first message arrives.

func registerUserWithMetadata() {
    let kmUser = KMUser()
    kmUser.userId = “12345”
    kmUser.applicationId = “YOUR_APP_ID”
    kmUser.displayName = “Alex Johnson”
    kmUser.email = “alex@example.com”

    let metadata = NSMutableDictionary()
    metadata[“plan”] = “Pro”
    metadata[“appVersion”] = “2.4.1”
    metadata[“currentScreen”] = “Order Details”
    metadata[“lastOrderId”] = “ORD-98231”

    kmUser.metadata = metadata

    Kommunicate.registerUser(kmUser) { response, error in
        if let error = error {
            print(“Registration failed: \(error.localizedDescription)”)
            return
        }

        print(“Registered with metadata”)
    }
}

Step 9: Create a custom conversation flow

The basic createAndShowConversation method is enough for many use cases. For more control, use KMConversationBuilder to route conversations to a specific AI agent, assign the conversation to a human agent or team, set a conversation title, or pass screen-level metadata.

func createOrderSupportConversation() {
    guard let topViewController = UIApplication.topViewController() else {
        return
    }

    let conversation = KMConversationBuilder()
        .withBotIds([“YOUR_AI_AGENT_ID”])
        .withConversationAssignee(“YOUR_AI_AGENT_ID”)
        .withMetaData([
            “source”: “iOS App”,
            “screen”: “Order Details”,
            “category”: “Order Support”
        ])
        .withConversationTitle(“Order Support”)
        .useLastConversation(false)
        .build()

    Kommunicate.createConversation(conversation: conversation) { result in
        switch result {
        case .success(let conversationId):
            Kommunicate.showConversationWith(
                groupId: conversationId,
                from: topViewController,
                showListOnBack: false
            ) { success in
                print(“Conversation shown: \(success)”)
            }

        case .failure(let error):
            print(“Failed to create conversation: \(error)”)
        }
    }
}

This pattern is useful when the support intent varies by screen. A user opening chat from a billing screen has a different need than one opening it from account settings. Passing screen and category metadata lets the selected AI agent respond with that context from the first message.

Step 10: Customize the chat experience

You can customize the Kommunicate chat UI so it feels like part of your iOS app. For example, to hide the bottom Start New Conversation button, add this inside AppDelegate after SDK initialization:

import UIKit
import Kommunicate

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        Kommunicate.setup(applicationId: “YOUR_APP_ID”)

        Kommunicate.defaultConfiguration.hideBottomStartNewConversationButton = true

        return true
    }
}

You can also configure attachment options, FAQ buttons, conversation info, toolbar subtitle, audio options, and navigation behavior. For most apps, start with a minimal configuration: match the support entry point to your app design, hide unused attachment options, and keep escalation visible.

Step 11: Add Push Notifications

Push notifications let you bring users back to an open conversation when a reply arrives. For push notification handling, your AppDelegate should conform to UNUserNotificationCenterDelegate:

import UIKit
import Kommunicate
import UserNotifications

class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        Kommunicate.setup(applicationId: “YOUR_APP_ID”)

        UNUserNotificationCenter.current().delegate = self

        return true
    }
}

You will also need to complete the APNs setup from the Kommunicate dashboard and your Apple Developer account. Test push notifications on a real device, not the simulator.

Where should you add the chatbot in your iOS app?

If a screen creates support questions, add contextual support there.

High-value placement points include: 

  1. The account screen (login issues, plan questions, subscription changes)
  2. Order or booking details (delivery updates, cancellations, refunds)
  3. Payment screens (failed payments, invoice questions)
  4. Help center screens (chatbot fallback when self-service does not resolve)
  5. Error or failure screens (when an action fails and the user needs immediate help).

Best Practices for SwiftUI Chatbot Integration

1. Pass User Context and Screen Metadata

If the user is logged in, pass their user ID, name, email, and relevant metadata before the conversation opens. If they are on a specific screen, include that context too: order ID, booking ID, payment status, app version. This prevents repetitive questioning and lets the AI agent start with useful context.

2. Keep Human Escalation Available

AI agents handle repetitive queries well, but users need a clear path to a human when the issue is complex, sensitive, or unresolved. Research shows that businesses deploying chatbots see satisfaction score improvements of around 24%, but primarily when escalation remains accessible.

3. Start With Common Queries

Do not automate every support workflow on day one. Start with safe, repetitive use cases, such as order status, refund policy, account setup, app navigation, appointment changes, or basic troubleshooting.

4. Test the Chatbot Like a User

Before publishing the app update, test the chatbot through actual app flows. Try support requests from different screens and verify that the conversation opens with the right context, routes to the correct AI agent, and escalates cleanly when needed.

Testing Checklist

Before shipping your SwiftUI chatbot integration, confirm:

  • Kommunicate SDK is installed correctly
  • App ID is set correctly in AppDelegate
  • AppDelegate is registered via UIApplicationDelegateAdaptor
  • Chat opens from the support button
  • Logged-in users are registered with a stable user ID
  • User and screen metadata are passed correctly
  • AI agent routing works as expected
  • Human handoff works where needed
  • Push notifications are tested on a real device
  • Camera, photo, microphone, and location permission prompts appear only when the corresponding feature is used
  • App does not crash if topViewController() returns nil

Common troubleshooting tips

Here are some issues you might face and how to solve them:

1. No Such Module Kommunicate

If you installed Kommunicate through CocoaPods, close the project and reopen the .xcworkspace file. Then clean and rebuild the project.

2. Chat Does Not Open

Check whether UIApplication.topViewController() is returning a valid view controller. Confirm that Kommunicate.setup(applicationId:) is called before any attempt to open a conversation.

3. User History Is Not Consistent

A new user ID for every session causes Kommunicate to treat the same user as a different person each time. Use a stable ID tied to your own auth system.

4. Permissions Are Missing

If users need to send photos, record audio, or share location, confirm the required keys are present in Info.plist.

5. Push Notifications Are Not Working

Check APNs certificate setup, device token registration, and Kommunicate dashboard configuration.

Conclusion

Adding an AI chatbot to a SwiftUI app gives users a direct way to get support without leaving the product. With Kommunicate, the setup starts with a simple support entry point, such as a Contact Support button, and can later expand into more contextual support flows across different screens.

The best way to begin is to choose the screen where users most often need help, connect it to Kommunicate.createAndShowConversation and test the full experience end to end. Once the basic flow is working, you can register logged-in users, pass metadata, add push notifications, and use KMConversationBuilder to route conversations to the right AI agent or support team.

This lets you start small, ship quickly, and build a more intelligent in-app support experience as you learn what your users need most.

Ready to add AI support to your iOS app? Sign up with Kommunicate and start building your SwiftUI chatbot integration today.

Write A Comment

You’ve unlocked 30 days for $0
Kommunicate Offer
Kommunicate Blog
×