मुख्य कंटेंट तक स्किप करें

Device applications चलाएँ

किसी application को शुरू या बंद करने से पहले device से मिली application list को authoritative source मानें।

आवश्यक शर्तें

  • Device connected हो और DeviceAppsAPI conform करता हो।
  • केवल deviceApps से मिले raw values को DeviceApp values में convert करें।

AI की सहायता से लागू करें

AI से बनाएँ

इस वर्कफ़्लो को AI से लागू करें

आधिकारिक “AIBuds डिवाइस ऐप्स प्रबंधित करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।

https://docs-aibuds.github.io/hi/skills/manage-aibuds-device-apps को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds डिवाइस ऐप्स प्रबंधित करें” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।
आधिकारिक स्किल देखें

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

Symbolउपयोग
deviceAppsउपलब्ध device applications के raw values।
startAppएक application शुरू करें।
stopAppएक application बंद करें।
stopAllAppsAndReturnToHomeScreenHome screen पर लौटें।
getCurrentForegroundAppForeground app पूछें।

Application values

SwiftObjective-CRaw valueअर्थ
.homeScreenAIBudsDeviceAppHomeScreen0x00Device home screen। इसे startApp या stopApp में न दें।
.teleprompterAIBudsDeviceAppTeleprompter0x01Teleprompter application।
.aiChatAIBudsDeviceAppAiChat0x02AI conversation application।
.navigationAIBudsDeviceAppNavigation0x03Navigation application।
.clockAIBudsDeviceAppClock0x04Clock application।
.translationAIBudsDeviceAppTranslation0x05Translation application।

उपयोग के उदाहरण

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

यह न मानें कि हर DeviceApp case हर device पर उपलब्ध है। Availability के लिए deviceApps, authoritative foreground state के लिए getCurrentForegroundApp उपयोग करें और product-specific handling के लिए device status codes सुरक्षित रखें।