Skip to main content

Gabber iOS SDK Documentation

Welcome to the Gabber iOS SDK! This guide will help you integrate Gabber into your iOS applications and utilize its features for AI voice, moderation, and text chat functionalities. The following example app demonstrates how to use the SDK effectively.

This tutorial is based on the iOS SDK and this sample app.

Getting Started

Prerequisites

Ensure you have the following installed:

  • Xcode 14 or later
  • Swift 5.5 or later
  • A Gabber API Key

Installation

To install the Gabber SDK:

  1. Add the SDK to your project dependencies by referencing the Gabber SDK Package:

Add Gabber to Your Package.swift

let package = Package(
name: "YourApp",
dependencies: [
.package(url: "https://github.com/gabber-dev/sdk-swift.git", from: "1.0.0")
],
targets: [
.target(
name: "YourApp",
dependencies: ["Gabber"]
)
]
)
  1. Import the SDK into your Swift files where needed:
import Gabber

Example Project Structure

The example app code is organized as follows:

  • GabberExample.xcodeproj: Xcode project configuration.
  • ContentView.swift: Main user interface for the app.
  • GabberExampleApp.swift: App entry point.
  • GabberViewModel.swift: ViewModel for handling Gabber logic.
  • Info.plist: App configuration settings.
  • GabberExampleTests.swift: Unit tests for the example app.
  • GabberExampleUITests.swift: UI tests for the example app.
  • GabberExampleUITestsLaunchTests.swift: Launch tests for UI scenarios.

Gabber SDK Core Files

The SDK includes the following key components:

  • Api.swift: Core API methods for interacting with Gabber services.
  • PublicTypes.swift: Definitions of public types used in the SDK.
  • Session.swift: Handles session management for users.
  • TrackVolumeVisualizer.swift: Provides functionality for visualizing audio input levels.
  • Generated/Client.swift: Auto-generated client for handling API calls.
  • Generated/Types.swift: Auto-generated type definitions used in API responses.

Integration Steps

1. Add Your Gabber API Key

Update Info.plist to include your Gabber API key:

<key>GabberAPIKey</key>
<string>Your_Gabber_API_Key</string>

2. Initialize Gabber in Your App

In GabberExampleApp.swift, initialize Gabber during app launch:

import SwiftUI
import Gabber

@main
struct GabberExampleApp: App {
init() {
Gabber.initialize(apiKey: "Your_Gabber_API_Key")
}

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

3. Set Up User Tracking

Use the GabberViewModel to manage user tokens and sessions. Example:

import Foundation
import Gabber

class GabberViewModel: ObservableObject {
@Published var userSession: String?

func startSession(for userId: String) {
let userToken = Gabber.generateUserToken(for: userId)
self.userSession = userToken
Gabber.startSession(with: userToken)
}
}

4. Add Chat or Voice Features

Integrate Gabber features into your UI in ContentView.swift:

import SwiftUI
import Gabber

struct ContentView: View {
@StateObject private var viewModel = GabberViewModel()

var body: some View {
VStack {
Text("Welcome to Gabber")
.font(.headline)
Button("Start Chat") {
viewModel.startSession(for: "example_user_id")
Gabber.openChat(for: "example_user_id")
}
}
.padding()
}
}

Testing

Unit Tests

The GabberExampleTests.swift file includes sample unit tests. Run these tests to verify your integration:

import XCTest
@testable import GabberExample

final class GabberExampleTests: XCTestCase {
func testUserSession() throws {
let viewModel = GabberViewModel()
viewModel.startSession(for: "test_user")
XCTAssertNotNil(viewModel.userSession)
}
}

UI Tests

UI tests are in GabberExampleUITests.swift and GabberExampleUITestsLaunchTests.swift. Use these to ensure the UI behaves as expected.

Additional Resources

Happy coding with Gabber!