-
Notifications
You must be signed in to change notification settings - Fork 0
Core Device Info Query Storage
Mr.P edited this page Aug 25, 2026
·
2 revisions
Request the latest storage information from a connected device, then read the updated storageInfo property.
Before querying storage information, 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 {
/// 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;
@endRequests the latest device storage information.
/// 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;| 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 |
|---|---|---|
usedSpaceInMB |
NSNumber |
Used storage space in megabytes. |
freeSpaceInMB |
NSNumber |
Remaining available storage space in megabytes. |
The method does not return storage data in its completion handler. After a successful request, read the updated storageInfo property.
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.h>
#import <AIBuds/AIBuds-Swift.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- Check
successbefore reading the refreshed property. - Use
errorfor failure details when the request does not succeed. - Handle a
nilstorageInfovalue even after a successful callback. - Do not assume fixed error codes unless they are documented for the target device.
-
Read After Success: Access
storageInfoonly after the query completes successfully. - Keep the SDK Unit: Treat both values as megabytes; do not interpret them as bytes.
-
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
StorageInfoModelresult. -
StorageInfoModelexposes only used and free space in megabytes. - The SDK does not expose a separate total-capacity property in this model.
- Storage information can change while media is recorded, 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