Ana içeriğe geç

Aygıt Uygulamalarını Çalıştırma

Bir uygulamayı başlatmadan veya durdurmadan önce yetkili kaynak olarak aygıtın sunduğu uygulama listesini kullanın.

Ön Koşullar

  • Aygıt bağlıdır ve DeviceAppsAPI protokolüne uyar.
  • Yalnızca deviceApps tarafından döndürülen ham değerleri DeviceApp değerlerine dönüştürün.

AI desteğiyle uygulayın

AI ile geliştirin

Bu iş akışını AI ile uygulayın

Resmî “AIBuds Cihaz Uygulamalarını Yönetme” becerisini kullanarak iş akışını uygulamanıza uyarlayın.

https://docs-aibuds.github.io/tr/skills/manage-aibuds-device-apps adresini okuyup yönergeleri izleyin. Bu beceriyle “AIBuds Cihaz Uygulamalarını Yönetme” iş akışını iOS projesinde uygulayıp doğrulayın.
Resmî beceriyi görüntüle

API Reference

Framework

AIBuds.xcframework

Protokol

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
        )?
    )
}

Semboller

SembolAmaç
deviceAppsKullanılabilir aygıt uygulamalarının ham değerleri.
startAppBir uygulamayı başlatır.
stopAppBir uygulamayı durdurur.
stopAllAppsAndReturnToHomeScreenAna ekrana döner.
getCurrentForegroundAppÖn plandaki uygulamayı sorgular.

Uygulama Değerleri

SwiftObjective-CHam değerAnlamı
.homeScreenAIBudsDeviceAppHomeScreen0x00Aygıt ana ekranı. startApp veya stopApp öğesine vermeyin.
.teleprompterAIBudsDeviceAppTeleprompter0x01Teleprompter uygulaması.
.aiChatAIBudsDeviceAppAiChat0x02AI sohbet uygulaması.
.navigationAIBudsDeviceAppNavigation0x03Navigasyon uygulaması.
.clockAIBudsDeviceAppClock0x04Saat uygulaması.
.translationAIBudsDeviceAppTranslation0x05Çeviri uygulaması.

Kullanım Örnekleri

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"))
}

Hata Yönetimi

Her DeviceApp case'inin her aygıtta bulunduğunu varsaymayın. Kullanılabilirlik için deviceApps, yetkili ön plan durumu için getCurrentForegroundApp kullanın ve ürüne özgü işleme için aygıt durum kodlarını koruyun.