Depolama Bilgilerini Sorgulama
Bağlı aygıttan en güncel depolama bilgilerini isteyin; ardından güncellenen storageInfo özelliğini okuyun.
Ön Koşullar
Depolama bilgilerini 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 {
/// 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;
@endÖrnek Yöntemi
Aygıtın en güncel depolama bilgilerini ister.
- 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;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 |
|---|---|---|
usedSpaceInMB | NSNumber | Megabayt cinsinden kullanılan depolama alanı. |
freeSpaceInMB | NSNumber | Megabayt cinsinden kalan kullanılabilir depolama alanı. |
Dönüş Değeri
Yöntem, depolama verilerini tamamlanma işleyicisinde döndürmez. Başarılı bir isteğin ardından güncellenen storageInfo özelliğini okuyun.
Kullanım Örnekleri
- 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);
}];
}
@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
nilolabilecekstorageInfodeğ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:
storageInfoözelliğine yalnızca sorgu başarıyla tamamlandıktan sonra erişin. - SDK Birimini Koruyun: Her iki değeri de megabayt olarak değerlendirin; bayt olarak yorumlamayın.
- 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
StorageInfoModelsonucu içermez. StorageInfoModelyalnızca megabayt cinsinden kullanılan ve boş alanı sunar.- SDK bu modelde toplam kapasite için ayrı bir özellik sunmaz.
- Medya kaydedilirken, içe aktarılırken veya silinirken depolama bilgileri değişebilir.