Skip to main content

Manage Device Applications

Use the device-provided application list as the source of truth before starting or stopping an application.

Prerequisites

  • The device is connected and conforms to DeviceAppsAPI.
  • Convert only raw values returned by deviceApps into DeviceApp values.

Implement with AI Assistance

Build with AI

Implement this workflow with AI

Use the official Manage AIBuds Device Apps skill to adapt this workflow to your app.

Read and follow https://docs-aibuds.github.io/skills/manage-aibuds-device-apps. Use it to implement Manage AIBuds Device Apps in this iOS project and verify the result.
View official skill

API Reference

Framework

AIBuds.xcframework

Protocol

Swift
/// The protocol for device apps API. (Device Side Applications)
protocol DeviceAppsAPI: DeviceAPI {
    /// List of apps installed on the device, each element is an `NSNumber` wrapping the raw value of `DeviceApp`.
    var deviceApps: [NSNumber]? { get }

    /// Start the device side application.
    /// - Parameters:
    ///   - app: The app to start.
    ///   - completion: Reports success, the device status code, and an optional error.
    func startApp(_ app: DeviceApp, completion: AIBudsStatusCodeCompletionHandler?)

    /// Stop the device side application.
    /// - Parameters:
    ///   - app: The app to stop.
    ///   - completion: Reports success, the device status code, and an optional error.
    func stopApp(_ app: DeviceApp, completion: AIBudsStatusCodeCompletionHandler?)

    /// Stop all running applications and return to the home screen.
    /// - Parameter completion: Reports success and an optional error.
    func stopAllAppsAndReturnToHomeScreen(_ completion: AIBudsCompletionHandler?)

    /// Get the current foreground application.
    /// - Parameter completion: Reports success, the foreground app raw value, and an optional error.
    func getCurrentForegroundApp(
        _ completion: (
            (
                _ success: Bool,
                _ app: NSNumber?,
                _ error: NSError?
            ) -> Void
        )?
    )
}

Symbols

SymbolPurpose
deviceAppsRaw values for available device applications.
startAppStart one application.
stopAppStop one application.
stopAllAppsAndReturnToHomeScreenReturn to the home screen.
getCurrentForegroundAppQuery the foreground app.

Application Values

SwiftObjective-CRaw valueMeaning
.homeScreenAIBudsDeviceAppHomeScreen0x00Device home screen. Do not pass it to startApp or stopApp.
.teleprompterAIBudsDeviceAppTeleprompter0x01Teleprompter application.
.aiChatAIBudsDeviceAppAiChat0x02AI conversation application.
.navigationAIBudsDeviceAppNavigation0x03Navigation application.
.clockAIBudsDeviceAppClock0x04Clock application.
.translationAIBudsDeviceAppTranslation0x05Translation application.

Usage Examples

Swift
guard let device = device as? DeviceAppsAPI else { return }

let apps = (device.deviceApps ?? []).compactMap {
    DeviceApp(rawValue: $0.intValue)
}

guard let app = apps.first else {
    print("No device application is available")
    return
}

device.startApp(app) { success, statusCode, error in
    guard success else {
        print(error?.localizedDescription ?? "Application failed to start")
        return
    }
    print("Application started: \(statusCode?.stringValue ?? "Unavailable")")
}

device.getCurrentForegroundApp { success, rawApp, error in
    let foreground = rawApp.flatMap { DeviceApp(rawValue: $0.intValue) }
    print(
        success
            ? "Foreground: \(String(describing: foreground))"
            : (error?.localizedDescription ?? "Query failed"))
}

Error Handling

Do not assume every DeviceApp case exists on every device. Use deviceApps for availability, getCurrentForegroundApp for authoritative foreground state, and preserve device status codes for product-specific handling.