Skip to main content

Quick Start

This guide will help you get started with AIBuds SDK iOS quickly. We'll walk you through the basic setup and show you how to perform common tasks.

Implement with AI Assistance

Build with AI

Implement this workflow with AI

Use the official Integrate AIBuds SDK skill to adapt this workflow to your app.

Read and follow https://docs-aibuds.github.io/skills/integrate-aibuds-sdk. Use it to implement Integrate AIBuds SDK in this iOS project and verify the result.
View official skill

Step 1: Import the SDK

Import the main header in any file where you use the SDK:

Swift
import AIBuds
import ABMate
import AIBudsLog
import AIBudsAIFoundation
import AIBudsAI
import AIBudsStarBurst
import AIBudsMagicHelper
import AIBudsVoiceAssistant
import AIBudsXLFacility
import AIBudsLiveStream
import AIBudsCrashReporter
import AIBudsAllInOne

Step 2: Initialize the SDK

First, you need to initialize the AIBuds SDK in your application. This is typically done in your AppDelegate or SceneDelegate:

Swift
// AppDelegate.swift

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    // Initialize AIBuds SDK with Full Installation
    initWithFullInstallation()

    // Initialize AIBuds SDK with Custom Installation
    //initWithCustomInstallation()

    return true
}

/// Initialize AIBuds SDK with Full Installation
private func initWithFullInstallation() {
    // Initialize AIBuds SDK
    if !AllInOneSDK.init(withDelegate: self) {
        print("Failed to initialize AIBuds AllInOne SDK.")
    }

    // Install crash reporter
    AllInOneSDK.installCrashReporter { reportFilePath in
        print("Last crash report path: \(reportFilePath ?? "")")
    } reportListUpdateCallback: {
        print("Crash report list updated")
    }
    // Set user info for crash reporter
    CrashReporterSDK.setUserInfo("Tom", forKey: "User Name")
    CrashReporterSDK.setUserInfo("199", forKey: "User ID")

    // Start AI dashboard
    AllInOneSDK.startAIDashboard()
}

/// Initialize AIBuds SDK with Custom Installation
private func initWithCustomInstallation() {
    // Set XLFacility plugin
    AIBudsLogSDK.setXLFacilityPlugin(XLFacilitySDK.shared())

    // Initialize AIBuds SDK with all Ble SDKs you would like to integrate into your app
    let sdkConfiguration = SDKConfiguration.default()
    // Set log level to verbose
    sdkConfiguration.logLevel = .verbose
    let success = AIBudsSDK.initialize(
        [ABMateSDK.shared()],
        configuration: sdkConfiguration,
        delegate: self)
    if !success {
        print("AIBudsSDK initialize failed.")
    }

    // Install StarBurst AI plugin
    AIBudsSDK.setStarBurstAIPlugin(StarBurstAuthPlugin.shared())
    // Install MltCloud AI plugin
    AIBudsSDK.setMltCloudAIPlugin(MltCloudAuthPlugin.shared())

    // Install OnDeviceVoiceAssistant plugin
    AIBudsSDK.setOnDeviceVoiceAssistantPlugin(OnDeviceVoiceAssistantPlugin.shared())

    // Initialize AI SDK with all AI SDKs you would like to integrate into your app
    let aiSuccess = AIBudsAISDK.initialize([
        StarBurstSDK.shared(),
        MagicHelperSDK.shared(),
    ])
    if !aiSuccess {
        print("AIBudsAISDK initialize failed.")
    }

    // Install crash reporter
    CrashReporterSDK.installCrashReporter { reportFilePath in
        print("Last crash report path: \(reportFilePath ?? "")")
    } reportListUpdateCallback: {
        print("Crash report list updated")
    }
    // Set user info for crash reporter
    CrashReporterSDK.setUserInfo("Tom", forKey: "User Name")
    CrashReporterSDK.setUserInfo("199", forKey: "User ID")

    // Start AI dashboard
    AIDashboardSDK.start()
}

Step 3: Scan for Devices

To connect to an AIBuds device, you first need to scan for available devices:

Swift
// Start scanning for devices
AIBudsSDK.startScanning(
    deviceFoundHandler: { device, isExistingDevice in
        print("Found device: \(device.name), RSSI: \(device.rssi)")
        print(isExistingDevice ? "Already stored" : "New device")
    },
    completion: {
        print("Scanning stopped")
    }
)

Step 4: Add a Device

After scanning, you can add a discovered device to "My Devices" so it persists across app launches. Convert the FoundDeviceConvertible returned by the scan through makeStorableDeviceFromDiscovered(_:), then save it through StoredDevicesMgr:

Swift
func store(_ discoveredDevice: FoundDeviceConvertible) {
    // Convert the SDK scan result into a persistent device.
    guard let device = AIBudsSDK.makeStorableDeviceFromDiscovered(discoveredDevice) else {
        return
    }

    // Optional app-owned display information.
    device.screenName = device.name
    device.thumbnail = UIImage(named: "icon.glasses")
    device.customContent = "Smart Glasses"

    if StoredDevicesMgr.addDevice(device) {
        AIBudsSDK.stopScanning()
        navigationController?.popViewController(animated: true)
    }
}

Step 5: Connect to a Device

With a stored device ready, connect to it using ConnectParams. You can pass AI auth parameters so the SDK authenticates with your AI providers during connection:

Swift
let device = devices[indexPath.item]

let param = ConnectParams()
let aiAuthParams = AIAuthParams()

// StarBurst AI auth
let starBurstAuthParams = StarBurstAIAuthParams()
starBurstAuthParams.productId = configs["STARBURST_PRODUCTID"]
if let ppeEnv = configs["STARBURST_PPEENV"] as? String, !ppeEnv.isEmpty {
    starBurstAuthParams.ppeEnv = ppeEnv
}
aiAuthParams.starburst = starBurstAuthParams

// MltCloud AI auth
let mltCloudAuthParams = MltCloudAIAuthParams()
mltCloudAuthParams.channelId = configs["MLTCLOUD_CHANNELID"]
aiAuthParams.mltcloud = mltCloudAuthParams

param.aiAuthParams = aiAuthParams
param.userId = "199"

// Connect to the device
device.connect(param)

Step 6: Send Commands

Once connected, you can send commands to the device:

Swift
// Example: Set device time
guard let device = device as? DeviceInfoAPI else { return }
let date = Date()
device.setDeviceTime(date) { success, statusCode, error in
    if success {
        print("Device time set successfully")
    } else {
        print("Failed to set device time: \(error?.localizedDescription ?? "Unknown error")")
    }
}

Step 7: Handle Device Delegate

Adopt the DeviceDelegate protocol to receive connection lifecycle device delegate events. All methods are @objc optional — implement only the callbacks you need:

Swift
// Mark your class as the device's delegate
device.delegate = self

// Implement the optional delegate methods
extension YourViewController: DeviceDelegate {
    func didStartConnectingDevice(_ device: DeviceConvertible) {
        print("Connecting to \(device.name)…")
    }

    func didConnectedToDevice(_ device: DeviceConvertible) {
        print("Connected to \(device.name)")
    }

    func didFailToConnectDevice(_ device: DeviceConvertible?, error: NSError?) {
        print("Failed to connect: \(error?.localizedDescription ?? "Unknown error")")
    }

    func device(_ device: DeviceConvertible?, didDisconnectWithError error: NSError?) {
        if let error {
            print("Disconnected with error: \(error.localizedDescription)")
        } else {
            print("Disconnected")
        }
    }

    func deviceDidReady(_ device: DeviceConvertible) {
        print("Device ready: \(device.name)")
    }

    /// ... other delegate methods...
}

Step 8: Disconnect from a Device

When you're done with a device, you should disconnect from it:

Swift
// Disconnect from a device
device.disconnect()

Example App

For a complete example, check out the AIBudsSDK-Demo project, which demonstrates how to use the SDK in a real-world application.

Next Steps

Now that you've learned the basics, you can explore the SDK's more advanced features: