मीडिया फ़ाइलों की संख्या पूछें
जुड़े डिवाइस से photo, video और audio की नवीनतम संख्या माँगें, फिर अपडेट हुई mediaCountInfo property पढ़ें।
पहले की आवश्यकताएँ
Media counts पूछने से पहले सुनिश्चित करें:
- डिवाइस 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 {
/// 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;
@endInstance method
डिवाइस में रखी media files की नवीनतम संख्या माँगता है।
- 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? | Request पूरा होने पर call होने वाला optional completion handler। |
Callback पैरामीटर:
| नाम | प्रकार | विवरण |
|---|---|---|
success | Bool / BOOL | Request सफल हो तो true, अन्यथा false। |
error | NSError? | Request असफल हो तो error details, अन्यथा nil। |
Result properties:
| Property | प्रकार | विवरण |
|---|---|---|
photoCount | NSNumber | Photos की संख्या। |
videoCount | NSNumber | Videos की संख्या। |
audioCount | NSNumber | Audio files की संख्या। |
Return value
Method completion handler में media counts return नहीं करता। सफल request के बाद अपडेट हुई mediaCountInfo property पढ़ें।
उपयोग के उदाहरण
- 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);
}];
}
@endError handling
- Refresh हुई property पढ़ने से पहले
successजाँचें। - Request असफल होने पर details के लिए
errorउपयोग करें। - सफल callback के बाद भी
nilमिलने की स्थिति संभालें, क्योंकिmediaCountInfoउपलब्ध न हो सकता है। - लक्ष्य डिवाइस के लिए documented न होने वाले fixed error codes न मानें।
बेहतर तरीके
- सफलता के बाद पढ़ें: Query सफल होने के बाद ही
mediaCountInfoपढ़ें। - Published fields उपयोग करें: Photo, video और audio counts अलग-अलग पढ़ें।
- Protocol conformance जाँचें:
DeviceInfoAPIsupport की पुष्टि करें। - UI main queue पर अपडेट करें: Completion से आने वाले UIKit updates main queue पर भेजें।
ध्यान देने योग्य बातें
- Completion handler request status देता है; उसमें
MediaCountInfoModelresult नहीं होता। MediaCountInfoModelphoto, video और audio counts कोNSNumbervalues के रूप में देता है।- SDK इस model में
totalCountproperty नहीं देता। - Files capture, import या delete होने के दौरान media counts बदल सकते हैं।