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

Device firmware update

Device OTA supported AIBuds device का main firmware update करता है। यह Camera OTA से अलग है, जो device का camera module update करता है।

Host app update check, download, integrity verification और device-model validation पूरा करके compatible local firmware package देता है। SDK package transfer और install करता है, startup result बताता है, 0.0 से 1.0 तक progress देता है और average transfer speed के साथ final result लौटाता है। startHandler केवल task शुरू होने की पुष्टि है; authoritative final result के लिए completionHandler उपयोग करें।

Animated workflow

Device OTA delivery path

Validate the product input first, then let the SDK start, transfer, and complete the main-firmware update.

Host app

Validate Package

Verify integrity, firmware compatibility, and the readable local path.

Host app

Check Battery

Compare the current device battery with otaBatteryLimit immediately before starting.

Host app

Select Protocol

Use the default overload or the product-required OTA protocol configuration.

SDK

Start OTA Task

Submit the local package and distinguish start acceptance from final success.

SDK + device

Transfer & Install

Keep the connection stable while normalized progress advances from 0.0 to 1.0.

progress · 0.0...1.0
Authoritative result

Final Completion

Use success, average transfer speed, and error from the completion handler.

A successful start callback is not a successful firmware update; wait for final completion.

आवश्यक शर्तें

  • Device connected हो और DeviceOtaAPI conform करता हो।
  • समर्थित protocol तय करने के लिए otaProtocolCapability का उपयोग करें; firmware filename से अनुमान न लगाएँ।
  • FitCloud Pro या Jieli के लिए डिवाइस connect करने से पहले matching OTA plugin install और register करें।
  • Device battery कम-से-कम otaBatteryLimit percent हो।
  • filePath इस device के सही और पूरे firmware package को point करता हो।
  • Completion तक app active और connection stable रखें।

AI की सहायता से लागू करें

AI से बनाएँ

इस वर्कफ़्लो को AI से लागू करें

आधिकारिक “AIBuds फ़र्मवेयर अपडेट करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।

https://docs-aibuds.github.io/hi/skills/update-aibuds-firmware को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds फ़र्मवेयर अपडेट करें” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।
आधिकारिक स्किल देखें

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds
import AIBudsFoundation

Protocol की घोषणा

Swift
/// The protocol for device OTA upgrade API.
protocol DeviceOtaAPI: DeviceAPI {
    /// The OTA protocol capability reported by the device.
    /// Defaults to `.abmate` when the device does not report this capability.
    var otaProtocolCapability: OtaProtocolCapability { get }

    /// OTA battery limit, 0...100, unit: percent.
    var otaBatteryLimit: Int { get }

    /// Start OTA upgrade.
    /// - Parameters:
    ///   - filePath: Upgrade file path.
    ///   - startHandler: Upgrade start callback.
    ///     - success: Whether the OTA task started successfully.
    ///     - error: Failure information, or `nil` if the task started.
    ///   - progressHandler: Upgrade progress callback.
    ///     - progress: Progress value in the range `0.0...1.0`.
    ///   - completionHandler: Final upgrade completion callback.
    ///     - success: Whether the upgrade succeeded.
    ///     - avgSpeed: Average transfer speed in kB/s.
    ///     - error: Failure information, or `nil` if the upgrade succeeded.
    func startOta(
        withFilePath filePath: String,
        startHandler: AIBudsOtaStartCompletionHandler?,
        progressHandler: AIBudsOtaProgressHandler?,
        completionHandler: AIBudsOtaCompletionHandler?
    )

    /// Start OTA upgrade with an explicit transfer protocol configuration.
    /// - Parameters:
    ///   - filePath: Upgrade file path.
    ///   - configuration: OTA protocol configuration.
    ///   - startHandler: Upgrade start callback.
    ///     - success: Whether the OTA task started successfully.
    ///     - error: Failure information, or `nil` if the task started.
    ///   - progressHandler: Upgrade progress callback.
    ///     - progress: Progress value in the range `0.0...1.0`.
    ///   - completionHandler: Final upgrade completion callback.
    ///     - success: Whether the upgrade succeeded.
    ///     - avgSpeed: Average transfer speed in kB/s.
    ///     - error: Failure information, or `nil` if the upgrade succeeded.
    func startOta(
        withFilePath filePath: String,
        configuration: OtaConfiguration,
        startHandler: AIBudsOtaStartCompletionHandler?,
        progressHandler: AIBudsOtaProgressHandler?,
        completionHandler: AIBudsOtaCompletionHandler?
    )
}

API Reference में otaProtocolCapability, otaBatteryLimit और startOta overloads देखें।

डिवाइस क्षमता

डिवाइस ready होने के बाद otaProtocolCapability पढ़ें और selectable protocols को इसके अनुसार सीमित करें।

SwiftObjective-CRaw valueसमर्थित protocol
.noneAIBudsOtaProtocolCapabilityNone-1OTA support report नहीं हुआ।
.abmateAIBudsOtaProtocolCapabilityAbmate0ABMate। Capability report न होने पर यह fallback भी है।
.fitcloudProAIBudsOtaProtocolCapabilityFitcloudPro1FitCloud Pro। FitCloud Pro plugin आवश्यक है।
.abmateAndFitcloudProAIBudsOtaProtocolCapabilityAbmateAndFitcloudPro2ABMate और FitCloud Pro; केवल registered choices दिखाएँ।
.jieliAIBudsOtaProtocolCapabilityJieli3Jieli single-bank OTA। Jieli plugin आवश्यक है।

OTA configuration

OtaConfiguration configured overload का BLE OTA protocol चुनता है। इसकी otaProtocol property default रूप से .abmate है।

SwiftObjective-CRaw valueअर्थ
.abmateAIBudsOtaProtocolKindAbmate0ABMate OTA protocol।
.fitcloudProAIBudsOtaProtocolKindFitcloudPro1FitCloud Pro OTA protocol।
.jieliAIBudsOtaProtocolKindJieli2Jieli single-bank OTA protocol।

Firmware file देखकर protocol का अनुमान न लगाएँ। Connected device और product integration द्वारा required protocol उपयोग करें।

वैकल्पिक OTA Plugins

FitCloud Pro और Jieli अलग CocoaPods subspecs हैं। SDK आवश्यक BLE characteristics discover और subscribe कर सके, इसके लिए डिवाइस connect करने से पहले plugins register करें। AIBudsSDK/AllInOne दोनों को अपने-आप install और register करता है।

Ruby
pod 'AIBudsSDK/FitCloudProOTA'
pod 'AIBudsSDK/JieliOTA'
Swift
import AIBuds
import AIBudsFitCloudProOTA
import AIBudsJieliOTA

AIBudsSDK.registerOtaPlugin(FitCloudProOtaSDK.otaPlugin)
AIBudsSDK.registerOtaPlugin(JieliOtaSDK.otaPlugin)

Modular integration में केवल वही implementations register करें जो product उपलब्ध कराता है। समान OtaProtocolKind के लिए बाद का registration पिछले plugin को replace कर देता है। Availability जाँचने के लिए AIBudsSDK.otaPlugin(for:) या unregister करने के लिए AIBudsSDK.removeOtaPlugin(for:) उपयोग करें।

Return value

कोई overload सीधे value return नहीं करता। startHandler task शुरू होने, progressHandler normalized progress और completionHandler authoritative final result व average transfer speed देता है।

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

Swift
guard let device = device as? DeviceOtaAPI else { return }
guard deviceBatteryPercent >= device.otaBatteryLimit else {
    print("Charge the device before updating")
    return
}

device.startOta(
    withFilePath: firmwareURL.path,
    startHandler: { success, error in
        if !success { print(error?.localizedDescription ?? "OTA failed to start") }
    },
    progressHandler: { progress in
        print("OTA: \(Int(progress * 100))%")
    },
    completionHandler: { success, averageSpeed, error in
        print(
            success
                ? "OTA completed at \(averageSpeed) kB/s"
                : (error?.localizedDescription ?? "OTA failed"))
    })

OTA protocol स्पष्ट रूप से चुनें

Configured overload तभी उपयोग करें जब product integration को connected device का required OTA protocol पता हो।

Swift
let configuration = OtaConfiguration()
configuration.otaProtocol = .fitcloudPro

device.startOta(
    withFilePath: firmwareURL.path,
    configuration: configuration,
    startHandler: { success, error in
        if !success {
            print(error?.localizedDescription ?? "OTA failed to start")
        }
    },
    progressHandler: { progress in
        print("OTA: \(Int(progress * 100))%")
    },
    completionHandler: { success, averageSpeed, error in
        print(
            success
                ? "OTA completed at \(averageSpeed) kB/s"
                : (error?.localizedDescription ?? "OTA failed"))
    }
)

Error handling

OTA errors AIBudsSDK.OtaErrorDomain और SdkOtaErrorCode उपयोग करते हैं।

Codesसामान्य कारण
unknownSDK error को अधिक स्पष्ट category में नहीं रख सकता।
otaTaskAlreadyRunningदूसरा OTA task पहले से active है।
otaTaskCreateFailedDueToFileNotFoundLocal firmware path मौजूद नहीं है।
otaTaskStartFailedDueToFileReadError, otaTaskStartFailedDueToFileHandleCreateErrorPackage खोला या पढ़ा नहीं जा सकता।
otaTaskStartFailedDueToInvalidFileHashDataFirmware hash data invalid है।
otaTaskStartFailedDueToGetOtaInfoErrorRequired OTA metadata नहीं मिल पाया।
otaTaskStartFailedDueToInvalidOffsetAddress, otaTaskStartFailedDueToInvalidBlockSizeTransfer metadata invalid है।
otaTaskStartFailedDueToNotAllowUpdateDevice की मौजूदा state update allow नहीं करती।
otaTaskSendDataFailedDueToFileHandleIsNil, otaTaskSendDataFailedDueToSeekFileHandleFailed, otaTaskSendDataFailedDueToReadFileDataFailed, otaTaskSendDataFailedDueToOtaInfoIsNilSDK firmware data पढ़ना या भेजना जारी नहीं रख सकता।
otaTaskFailedDueToDeviceReportKeyMismatch, otaTaskFailedDueToDeviceReportCrcError, otaTaskFailedDueToDeviceReportSeqError, otaTaskFailedDueToDeviceReportDataLengthErrorDevice transferred data reject करता है या integrity/sequence problem report करता है।
otaTaskFailedDueToDeviceDisconnect, otaTaskFailedDueToTimeoutDevice disconnect हुआ या operation timeout हुआ।

startHandler failure को transfer शुरू होने के बाद की failure से अलग रखें। Unverified package से automatic retry न करें; पहले device model, firmware version, package integrity, battery, protocol selection और connection फिर validate करें।

बेहतर तरीके

  1. SDK call करने से पहले update discovery, download, signature या integrity verification और device-model compatibility checks पूरे करें।
  2. otaBatteryLimit शुरू करने के तुरंत पहले जाँचें, केवल update UI दिखाते समय नहीं।
  3. OTA, Camera OTA, Media File Import या अन्य long-running device operations साथ न चलने दें।
  4. Callbacks दूसरी queue पर आ सकते हैं, इसलिए UI updates main queue पर dispatch करें।
  5. startHandler को केवल task-start confirmation मानें; completionHandler सफल होने से पहले upgrade success न दिखाएँ।
  6. Final completion तक app active और device connection stable रखें, फिर reconnect होने पर reported firmware version verify करें।

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

  • Progress 0.0...1.0 में normalized है; SDK result बदले बिना UI presentation को defensively clamp करें।
  • avgSpeed केवल final completion handler में kB/s में मिलता है।
  • OtaConfiguration.otaProtocol default रूप से .abmate है; .fitcloudPro या .jieli केवल तभी चुनें जब otaProtocolCapability और installed plugin support करें।
  • SDK OTA cancellation method expose नहीं करता। Demo का Cancel button केवल local UI state reset करता है; इसे SDK operation cancel करना न बताएँ।