Medya Sayılarını Sorgulama
Bağlı aygıttan en güncel fotoğraf, video ve ses dosyası sayılarını isteyin; ardından güncellenen mediaCountInfo özelliğini okuyun.
Ön Koşullar
Medya sayılarını sorgulamadan önce şunları doğrulayın:
- Aygıt bağlı ve kararlı durumdadır
- Aygıt
DeviceInfoAPIprotokolünü destekler
API Reference
Framework
AIBuds.xcframework
Import
SDK'yı kullanacağınız dosyalarda ana framework'ü içe aktarın:
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
İstek yöntemi ve sonuç özelliği DeviceInfoAPI içinde tanımlıdır.
- 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Örnek Yöntemi
Aygıtta depolanan medya için en güncel sayıları ister.
- 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;Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
completion | AIBudsCompletionHandler? | İstek tamamlandığında çağrılan isteğe bağlı tamamlanma işleyicisi. |
Geri Çağrı Parametreleri:
| Ad | Tür | Açıklama |
|---|---|---|
success | Bool / BOOL | İstek başarılıysa true; aksi halde false. |
error | NSError? | İstek başarısızsa hata ayrıntıları; aksi halde nil. |
Sonuç Özellikleri:
| Özellik | Tür | Açıklama |
|---|---|---|
photoCount | NSNumber | Fotoğraf sayısı. |
videoCount | NSNumber | Video sayısı. |
audioCount | NSNumber | Ses dosyası sayısı. |
Dönüş Değeri
Yöntem, medya sayılarını tamamlanma işleyicisinde döndürmez. Başarılı bir isteğin ardından güncellenen mediaCountInfo özelliğini okuyun.
Kullanım Örnekleri
- 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);
}];
}
@endHata Yönetimi
- Güncellenen özelliği okumadan önce
successdeğerini kontrol edin. - İstek başarısız olduğunda hata ayrıntıları için
errordeğerini kullanın. - Başarılı bir callback sonrasında
nilolabilecekmediaCountInfodeğerini güvenle yönetin. - Hedef aygıt için belgelenmedikçe sabit hata kodları varsaymayın.
En İyi Uygulamalar
- Başarıdan Sonra Okuyun:
mediaCountInfoözelliğine yalnızca sorgu başarıyla tamamlandıktan sonra erişin. - Sunulan Alanları Kullanın: Fotoğraf, video ve ses sayılarını ayrı ayrı okuyun.
- Protokol Uyumluluğunu Denetleyin: Aygıtın
DeviceInfoAPIdesteğini doğrulayın. - Arayüzü Ana Kuyrukta Güncelleyin: Tamamlanma geri çağrısına bağlı UIKit güncellemelerini ana kuyruğa aktarın.
Notlar
- Tamamlanma işleyicisi isteğin durumunu bildirir; bir
MediaCountInfoModelsonucu içermez. MediaCountInfoModel, fotoğraf, video ve ses sayılarınıNSNumberdeğerleri olarak sunar.- SDK bu modelde bir
totalCountözelliği sunmaz. - Dosyalar kaydedilirken, içe aktarılırken veya silinirken medya sayıları değişebilir.