본문으로 건너뛰기

기기 앱 제어

앱을 실행하거나 종료하기 전에 기기가 제공한 앱 목록을 기준으로 사용하세요.

사전 요구 사항

  • 기기가 연결되어 있고 DeviceAppsAPI를 준수합니다.
  • deviceApps가 반환한 raw value만 DeviceApp 값으로 변환합니다.

AI를 활용해 구현

AI로 구현

AI로 이 워크플로 구현

공식 “AIBuds 기기 앱 관리” 스킬을 사용해 앱에 맞게 구현하세요.

https://docs-aibuds.github.io/ko/skills/manage-aibuds-device-apps을 읽고 지침을 따르세요. 이 스킬로 “AIBuds 기기 앱 관리”을 이 iOS 프로젝트에 구현하고 검증하세요.
공식 스킬 보기

API 참고

프레임워크

AIBuds.xcframework

프로토콜

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

기호

기호용도
deviceApps사용할 수 있는 기기 앱의 raw value입니다.
startApp앱 하나를 실행합니다.
stopApp앱 하나를 종료합니다.
stopAllAppsAndReturnToHomeScreen홈 화면으로 돌아갑니다.
getCurrentForegroundApp현재 포그라운드 앱을 조회합니다.

앱 값

SwiftObjective-CRaw value의미
.homeScreenAIBudsDeviceAppHomeScreen0x00기기 홈 화면입니다. startApp 또는 stopApp에 전달하지 마세요.
.teleprompterAIBudsDeviceAppTeleprompter0x01텔레프롬프터 앱입니다.
.aiChatAIBudsDeviceAppAiChat0x02AI 대화 앱입니다.
.navigationAIBudsDeviceAppNavigation0x03길 안내 앱입니다.
.clockAIBudsDeviceAppClock0x04시계 앱입니다.
.translationAIBudsDeviceAppTranslation0x05번역 앱입니다.

사용 예제

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

오류 처리

모든 기기가 모든 DeviceApp case를 지원한다고 가정하지 마세요. 지원 여부는 deviceApps에서 확인하고, 신뢰할 수 있는 포그라운드 상태는 getCurrentForegroundApp으로 조회하며, 제품별 처리를 위해 기기 상태 코드를 보관하세요.