मुख्य कंटेंट तक स्किप करें

स्टोरेज जानकारी पूछें

जुड़े डिवाइस से नवीनतम storage जानकारी माँगें, फिर अपडेट हुई storageInfo property पढ़ें।

पहले की आवश्यकताएँ

Storage जानकारी पूछने से पहले सुनिश्चित करें:

  • डिवाइस connected और stable state में है
  • डिवाइस DeviceInfoAPI protocol का समर्थन करता है

API संदर्भ

फ्रेमवर्क

AIBuds.xcframework

Import

SDK उपयोग करने वाली files में main framework import करें:

Swift
import AIBuds

प्रोटोकॉल

Request method और result property DeviceInfoAPI में परिभाषित हैं।

Swift
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?
    )
}

Instance method

डिवाइस की नवीनतम storage जानकारी माँगता है।

Swift
/// 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?
)

पैरामीटर

पैरामीटरप्रकारविवरण
completionAIBudsCompletionHandler?Request पूरा होने पर call होने वाला optional completion handler।

Callback पैरामीटर:

नामप्रकारविवरण
successBool / BOOLRequest सफल हो तो true, अन्यथा false
errorNSError?Request असफल हो तो error details, अन्यथा nil

Result properties:

Propertyप्रकारविवरण
usedSpaceInMBNSNumberउपयोग हुई storage, MB में।
freeSpaceInMBNSNumberबची हुई storage, MB में।

Return value

Method completion handler में storage data return नहीं करता। सफल request के बाद अपडेट हुई storageInfo property पढ़ें।

उपयोग के उदाहरण

Swift
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")
        }
    }
}

Error handling

  1. Refresh हुई property पढ़ने से पहले success जाँचें।
  2. Request असफल होने पर details के लिए error उपयोग करें।
  3. सफल callback के बाद भी nil मिलने की स्थिति संभालें, क्योंकि storageInfo उपलब्ध न हो सकता है।
  4. लक्ष्य डिवाइस के लिए documented न होने वाले fixed error codes न मानें।

बेहतर तरीके

  1. सफलता के बाद पढ़ें: Query सफल होने के बाद ही storageInfo पढ़ें।
  2. SDK unit बनाए रखें: दोनों values को MB मानें, bytes नहीं।
  3. Protocol conformance जाँचें: DeviceInfoAPI support की पुष्टि करें।
  4. UI main queue पर अपडेट करें: Completion से आने वाले UIKit updates main queue पर भेजें।

ध्यान देने योग्य बातें

  • Completion handler request status देता है; उसमें StorageInfoModel result नहीं होता।
  • StorageInfoModel केवल उपयोग हुई और खाली जगह MB में देता है।
  • SDK इस model में अलग total-capacity property नहीं देता।
  • Media record, import या delete होने के दौरान storage जानकारी बदल सकती है।