feat:sdk 增加判断是否有新固件可用

This commit is contained in:
km2023
2026-04-13 18:41:46 +08:00
parent ba0a80e921
commit 920c24456a
3 changed files with 28 additions and 5 deletions

View File

@@ -61,15 +61,21 @@ let sdk = DuooomiBleSDK(config: .init(
| 方法 | 返回 | 说明 |
|------|------|------|
| `fetchLatestFirmware(identifier:status:)` | `FirmwareInfo?` | 查询最新固件nil 表示无可用版本 |
| `hasNewerFirmware(deviceVersion:serverVersion:)` | `Bool` | 对比版本号末尾10位时间戳判断是否有新版本。参数无效返回 false |
| `upgradeFirmware(fileUrl: String)` | `Void` | OTA 传输固件包到设备 |
```swift
// 1.
let info = try await sdk.fetchLatestFirmware()
// 2. OTA
if let info {
try await sdk.upgradeFirmware(fileUrl: info.fileUrl)
}
// 2.
let needUpdate = sdk.hasNewerFirmware(
deviceVersion: sdk.version, //
serverVersion: info?.version //
)
// 3. OTA
try await sdk.upgradeFirmware(fileUrl: info.fileUrl)
```
### 可观察状态