स्टोरेज जानकारी पूछें
जुड़े डिवाइस से नवीनतम storage जानकारी माँगें, फिर अपडेट हुई storageInfo property पढ़ें।
पहले की आवश्यकताएँ
Storage जानकारी पूछने से पहले सुनिश्चित करें:
- डिवाइस connected और stable state में है
- डिवाइस
DeviceInfoAPIprotocol का समर्थन करता है
API संदर्भ
फ्रेमवर्क
AIBuds.xcframework
Import
SDK उपयोग करने वाली files में main framework import करें:
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>प्रोटोकॉल
Request method और result property 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;
@endInstance method
डिवाइस की नवीनतम storage जानकारी माँगता है।
- 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? | Request पूरा होने पर call होने वाला optional completion handler। |
Callback पैरामीटर:
| नाम | प्रकार | विवरण |
|---|---|---|
success | Bool / BOOL | Request सफल हो तो true, अन्यथा false। |
error | NSError? | Request असफल हो तो error details, अन्यथा nil। |
Result properties:
| Property | प्रकार | विवरण |
|---|---|---|
usedSpaceInMB | NSNumber | उपयोग हुई storage, MB में। |
freeSpaceInMB | NSNumber | बची हुई storage, MB में। |
Return value
Method completion handler में storage data return नहीं करता। सफल request के बाद अपडेट हुई storageInfo property पढ़ें।
उपयोग के उदाहरण
- 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);
}];
}
@endError handling
- Refresh हुई property पढ़ने से पहले
successजाँचें। - Request असफल होने पर details के लिए
errorउपयोग करें। - सफल callback के बाद भी
nilमिलने की स्थिति संभालें, क्योंकिstorageInfoउपलब्ध न हो सकता है। - लक्ष्य डिवाइस के लिए documented न होने वाले fixed error codes न मानें।
बेहतर तरीके
- सफलता के बाद पढ़ें: Query सफल होने के बाद ही
storageInfoपढ़ें। - SDK unit बनाए रखें: दोनों values को MB मानें, bytes नहीं।
- Protocol conformance जाँचें:
DeviceInfoAPIsupport की पुष्टि करें। - UI main queue पर अपडेट करें: Completion से आने वाले UIKit updates main queue पर भेजें।
ध्यान देने योग्य बातें
- Completion handler request status देता है; उसमें
StorageInfoModelresult नहीं होता। StorageInfoModelकेवल उपयोग हुई और खाली जगह MB में देता है।- SDK इस model में अलग total-capacity property नहीं देता।
- Media record, import या delete होने के दौरान storage जानकारी बदल सकती है।