미디어 수량 조회
연결된 기기에 최신 사진, 동영상 및 오디오 수량을 요청한 뒤 갱신된 mediaCountInfo 속성을 읽습니다.
사전 요구 사항
미디어 수량을 조회하기 전에 다음을 확인하세요.
- 기기가 연결되어 안정적인 상태입니다.
- 기기가
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 {
/// Media file count information, including counts for photos, videos,
/// audio, etc.
var mediaCountInfo: MediaCountInfoModel? { get }
/// Request to query the device media count 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 requestQueryMediaCountInfo(
_ completion: AIBudsCompletionHandler?
)
}@protocol AIBudsDeviceInfoAPI <AIBudsDeviceAPI>
/// Media file count information, including counts for photos, videos,
/// audio, etc.
@property(nonatomic, readonly, strong) AIBudsMediaCountInfoModel *_Nullable mediaCountInfo;
/// Request to query the device media count 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)requestQueryMediaCountInfoWithCompletion:(AIBudsCompletionHandler _Nullable)completion;
@end인스턴스 메서드
기기에 저장된 미디어의 최신 수량을 요청합니다.
- Swift
- Objective-C
/// Request to query the device media count 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 requestQueryMediaCountInfo(
_ completion: AIBudsCompletionHandler?
)/// Request to query the device media count 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)requestQueryMediaCountInfoWithCompletion:(AIBudsCompletionHandler _Nullable)completion;매개변수
| 매개변수 | 타입 | 설명 |
|---|---|---|
completion | AIBudsCompletionHandler? | 요청이 끝날 때 호출되는 선택적 completion handler입니다. |
콜백 매개변수:
| 이름 | 타입 | 설명 |
|---|---|---|
success | Bool / BOOL | 요청이 성공하면 true, 실패하면 false입니다. |
error | NSError? | 요청 실패 상세 정보이며 성공하면 nil입니다. |
결과 속성:
| 속성 | 타입 | 설명 |
|---|---|---|
photoCount | NSNumber | 사진 수입니다. |
videoCount | NSNumber | 동영상 수입니다. |
audioCount | NSNumber | 오디오 파일 수입니다. |
반환 값
메서드의 completion handler는 미디어 수량을 반환하지 않습니다. 요청 성공 후 갱신된 mediaCountInfo 속성을 읽으세요.
사용 예제
- Swift
- Objective-C
import AIBuds
final class DeviceManager {
weak var device: DeviceConvertible?
func queryMediaCount() {
guard let device = device as? DeviceInfoAPI else {
print("Device does not support media-count queries")
return
}
device.requestQueryMediaCountInfo { success, error in
guard success else {
print("Media-count query failed: \(error?.localizedDescription ?? "Unknown error")")
return
}
guard let counts = device.mediaCountInfo else {
print("The device did not provide media-count information")
return
}
print("Photos: \(counts.photoCount)")
print("Videos: \(counts.videoCount)")
print("Audio files: \(counts.audioCount)")
}
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
@interface DeviceManager ()
@property(weak, nonatomic) id<AIBudsDeviceConvertible> device;
@end
@implementation DeviceManager
- (void)queryMediaCount {
id<AIBudsDeviceInfoAPI> device = (id<AIBudsDeviceInfoAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceInfoAPI)]) {
NSLog(@"Device does not support media-count queries");
return;
}
[device requestQueryMediaCountInfoWithCompletion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Media-count query failed: %@", error.localizedDescription ?: @"Unknown error");
return;
}
AIBudsMediaCountInfoModel *counts = device.mediaCountInfo;
if (!counts) {
NSLog(@"The device did not provide media-count information");
return;
}
NSLog(@"Photos: %@", counts.photoCount);
NSLog(@"Videos: %@", counts.videoCount);
NSLog(@"Audio files: %@", counts.audioCount);
}];
}
@end오류 처리
- 갱신된 속성을 읽기 전에
success를 확인하세요. - 요청이 실패하면
error에서 상세 정보를 확인하세요. - 콜백이 성공해도
nil인mediaCountInfo값을 처리하세요. - 대상 기기에 정의되지 않은 고정 오류 코드를 가정하지 마세요.
권장 사항
- 성공 후 읽기: 조회가 성공한 뒤에만
mediaCountInfo에 접근하세요. - 공개된 필드 사용: 사진, 동영상 및 오디오 수량을 각각 읽으세요.
- 프로토콜 확인: 기기가
DeviceInfoAPI를 지원하는지 확인하세요. - 메인 큐에서 UI 변경: completion에서 수행하는 UIKit 변경은 메인 큐로 전달하세요.
참고
- completion handler는 요청 상태만 보고하며
MediaCountInfoModel결과를 포함하지 않습니다. MediaCountInfoModel은 사진, 동영상 및 오디오 수량을NSNumber값으로 제공합니다.- SDK는 이 모델에
totalCount속성을 제공하지 않습니다. - 파일 촬영, 가져오기 또는 삭제 중에는 미디어 수량이 변경될 수 있습니다.