저장 공간 정보 조회
연결된 기기에 최신 저장 공간 정보를 요청한 뒤 갱신된 storageInfo 속성을 읽습니다.
사전 요구 사항
저장 공간 정보를 조회하기 전에 다음을 확인하세요.
- 기기가 연결되어 안정적인 상태입니다.
- 기기가
DeviceInfoAPI프로토콜을 지원합니다.
API 참고
프레임워크
AIBuds.xcframework
가져오기
SDK를 사용할 파일에서 메인 프레임워크를 가져옵니다.
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>프로토콜
요청 메서드와 결과 속성은 DeviceInfoAPI에 정의되어 있습니다.
- Swift
- Objective-C
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?
)
}@protocol AIBudsDeviceInfoAPI <AIBudsDeviceAPI>
/// Device storage information.
@property(nonatomic, readonly, strong) AIBudsStorageInfoModel *_Nullable storageInfo;
/// 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.
- (void)requestQueryStorageInfoWithCompletion:(AIBudsCompletionHandler _Nullable)completion;
@end인스턴스 메서드
기기의 최신 저장 공간 정보를 요청합니다.
- Swift
- Objective-C
/// 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?
)/// 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.
- (void)requestQueryStorageInfoWithCompletion:(AIBudsCompletionHandler _Nullable)completion;매개변수
| 매개변수 | 타입 | 설명 |
|---|---|---|
completion | AIBudsCompletionHandler? | 요청이 끝날 때 호출되는 선택적 completion handler입니다. |
콜백 매개변수:
| 이름 | 타입 | 설명 |
|---|---|---|
success | Bool / BOOL | 요청이 성공하면 true, 실패하면 false입니다. |
error | NSError? | 요청 실패 상세 정보이며 성공하면 nil입니다. |
결과 속성:
| 속성 | 타입 | 설명 |
|---|---|---|
usedSpaceInMB | NSNumber | 사용 중인 저장 공간(MB)입니다. |
freeSpaceInMB | NSNumber | 남은 저장 공간(MB)입니다. |
반환 값
메서드의 completion handler는 저장 공간 데이터를 반환하지 않습니다. 요청 성공 후 갱신된 storageInfo 속성을 읽으세요.
사용 예제
- Swift
- Objective-C
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")
}
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
@interface DeviceManager ()
@property(weak, nonatomic) id<AIBudsDeviceConvertible> device;
@end
@implementation DeviceManager
- (void)queryStorageInformation {
id<AIBudsDeviceInfoAPI> device = (id<AIBudsDeviceInfoAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceInfoAPI)]) {
NSLog(@"Device does not support storage queries");
return;
}
[device requestQueryStorageInfoWithCompletion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Storage query failed: %@", error.localizedDescription ?: @"Unknown error");
return;
}
AIBudsStorageInfoModel *storage = device.storageInfo;
if (!storage) {
NSLog(@"The device did not provide storage information");
return;
}
NSLog(@"Used storage: %@ MB", storage.usedSpaceInMB);
NSLog(@"Free storage: %@ MB", storage.freeSpaceInMB);
}];
}
@end오류 처리
- 갱신된 속성을 읽기 전에
success를 확인하세요. - 요청이 실패하면
error에서 상세 정보를 확인하세요. - 콜백이 성공해도
nil인storageInfo값을 처리하세요. - 대상 기기에 정의되지 않은 고정 오류 코드를 가정하지 마세요.
권장 사항
- 성공 후 읽기: 조회가 성공한 뒤에만
storageInfo에 접근하세요. - SDK 단위 유지: 두 값은 MB 단위이며 byte로 해석하지 마세요.
- 프로토콜 확인: 기기가
DeviceInfoAPI를 지원하는지 확인하세요. - 메인 큐에서 UI 변경: completion에서 수행하는 UIKit 변경은 메인 큐로 전달하세요.
참고
- completion handler는 요청 상태만 보고하며
StorageInfoModel결과를 포함하지 않습니다. StorageInfoModel은 사용 중인 용량과 여유 용량만 MB 단위로 제공합니다.- SDK는 이 모델에 전체 용량 속성을 별도로 제공하지 않습니다.
- 미디어 녹화, 가져오기 또는 삭제 중에는 저장 공간 정보가 변경될 수 있습니다.