본문으로 건너뛰기

저장 공간 정보 조회

연결된 기기에 최신 저장 공간 정보를 요청한 뒤 갱신된 storageInfo 속성을 읽습니다.

사전 요구 사항

저장 공간 정보를 조회하기 전에 다음을 확인하세요.

  • 기기가 연결되어 안정적인 상태입니다.
  • 기기가 DeviceInfoAPI 프로토콜을 지원합니다.

API 참고

프레임워크

AIBuds.xcframework

가져오기

SDK를 사용할 파일에서 메인 프레임워크를 가져옵니다.

Swift
import AIBuds

프로토콜

요청 메서드와 결과 속성은 DeviceInfoAPI에 정의되어 있습니다.

Swift
protocol DeviceInfoAPI: DeviceAPI {
    /// Device storage information.
    var storageInfo: StorageInfoModel? { get }

    /// Request to query the device storage information.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///   - success: `true` if the operation was successful; otherwise `false`.
    ///   - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestQueryStorageInfo(
        _ completion: AIBudsCompletionHandler?
    )
}

인스턴스 메서드

기기의 최신 저장 공간 정보를 요청합니다.

Swift
/// Request to query the device storage information.
/// - Parameters:
///   - completion: A closure that is called when the operation completes.
///   - success: `true` if the operation was successful; otherwise `false`.
///   - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func requestQueryStorageInfo(
    _ completion: AIBudsCompletionHandler?
)

매개변수

매개변수타입설명
completionAIBudsCompletionHandler?요청이 끝날 때 호출되는 선택적 completion handler입니다.

콜백 매개변수:

이름타입설명
successBool / BOOL요청이 성공하면 true, 실패하면 false입니다.
errorNSError?요청 실패 상세 정보이며 성공하면 nil입니다.

결과 속성:

속성타입설명
usedSpaceInMBNSNumber사용 중인 저장 공간(MB)입니다.
freeSpaceInMBNSNumber남은 저장 공간(MB)입니다.

반환 값

메서드의 completion handler는 저장 공간 데이터를 반환하지 않습니다. 요청 성공 후 갱신된 storageInfo 속성을 읽으세요.

사용 예제

Swift
import AIBuds

final class DeviceManager {
    weak var device: DeviceConvertible?

    func queryStorageInformation() {
        guard let device = device as? DeviceInfoAPI else {
            print("Device does not support storage queries")
            return
        }

        device.requestQueryStorageInfo { success, error in
            guard success else {
                print("Storage query failed: \(error?.localizedDescription ?? "Unknown error")")
                return
            }

            guard let storage = device.storageInfo else {
                print("The device did not provide storage information")
                return
            }

            print("Used storage: \(storage.usedSpaceInMB) MB")
            print("Free storage: \(storage.freeSpaceInMB) MB")
        }
    }
}

오류 처리

  1. 갱신된 속성을 읽기 전에 success를 확인하세요.
  2. 요청이 실패하면 error에서 상세 정보를 확인하세요.
  3. 콜백이 성공해도 nilstorageInfo 값을 처리하세요.
  4. 대상 기기에 정의되지 않은 고정 오류 코드를 가정하지 마세요.

권장 사항

  1. 성공 후 읽기: 조회가 성공한 뒤에만 storageInfo에 접근하세요.
  2. SDK 단위 유지: 두 값은 MB 단위이며 byte로 해석하지 마세요.
  3. 프로토콜 확인: 기기가 DeviceInfoAPI를 지원하는지 확인하세요.
  4. 메인 큐에서 UI 변경: completion에서 수행하는 UIKit 변경은 메인 큐로 전달하세요.

참고

  • completion handler는 요청 상태만 보고하며 StorageInfoModel 결과를 포함하지 않습니다.
  • StorageInfoModel은 사용 중인 용량과 여유 용량만 MB 단위로 제공합니다.
  • SDK는 이 모델에 전체 용량 속성을 별도로 제공하지 않습니다.
  • 미디어 녹화, 가져오기 또는 삭제 중에는 저장 공간 정보가 변경될 수 있습니다.