-
Notifications
You must be signed in to change notification settings - Fork 0
Core Device Info Query Media Count
Mr.P edited this page Aug 25, 2026
·
2 revisions
Request the latest photo, video, and audio counts from a connected device, then read the updated mediaCountInfo property.
Before querying media counts, ensure:
- The device is connected and in a stable state
- The device supports the
DeviceInfoAPIprotocol
AIBuds.xcframework
In the files where you want to use the SDK, import the main framework:
import AIBuds#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>The request method and result property are defined in DeviceInfoAPI.
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;
@endRequests the latest counts for media stored on the device.
/// 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;| Parameter | Type | Description |
|---|---|---|
completion |
AIBudsCompletionHandler? |
Optional completion handler called when the request finishes. |
Callback Parameters:
| Name | Type | Description |
|---|---|---|
success |
Bool / BOOL
|
true if the request succeeded; otherwise false. |
error |
NSError? |
Error details if the request failed; otherwise nil. |
Result Properties:
| Property | Type | Description |
|---|---|---|
photoCount |
NSNumber |
The number of photos. |
videoCount |
NSNumber |
The number of videos. |
audioCount |
NSNumber |
The number of audio files. |
The method does not return media counts in its completion handler. After a successful request, read the updated mediaCountInfo property.
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.h>
#import <AIBuds/AIBuds-Swift.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- Check
successbefore reading the refreshed property. - Use
errorfor failure details when the request does not succeed. - Handle a
nilmediaCountInfovalue even after a successful callback. - Do not assume fixed error codes unless they are documented for the target device.
-
Read After Success: Access
mediaCountInfoonly after the query completes successfully. - Use the Published Fields: Read photo, video, and audio counts independently.
-
Check Protocol Conformance: Confirm that the device supports
DeviceInfoAPI. - Update UI on the Main Queue: Dispatch completion-driven UIKit updates to the main queue.
- The completion handler reports request status; it does not contain a
MediaCountInfoModelresult. -
MediaCountInfoModelexposes photo, video, and audio counts asNSNumbervalues. - The SDK does not expose a
totalCountproperty in this model. - Media counts can change while files are captured, imported, or deleted.
AIBuds SDK documentation · Full documentation · API Reference
- Introduction
- Getting Started
- Core Concepts
-
Core Features
- Basic Features
- Device Info
- Find Device
- Physical Operations
- Work Mode
- Work Status
- Wear Detection
- Volume Control
- Music Control
- TWS
- Equalizer
- ANC
- Audio
- Camera
- Remote Camera
- File Import
- Teleprompter
- Segment Navigation
- Live Streaming
- Device Applications
- OTA
- Camera OTA
- Service Auth
- AI Services
- Voice Assistant
- Logging
- Advanced Topics
- Releases
- Troubleshooting