feat(sdk): 重命名 owner→brand 并在硬绑前校验设备品牌
- DuooomiBleConfig.owner → brand(语义:设备品牌名),HTTP header x-owner 不变 - bind() 前置 verifyBrand:缺 deviceInfo 先 getDeviceInfo,与 config.brand 严格匹配,不一致主动断连并抛 .brandMismatch - README 抹除软绑/对账/UpgradeRecord 等内部实现细节,仅保留厂商面向的公开 API(功能代码完全保留) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,8 +20,8 @@ final class DemoViewModel: NSObject, ObservableObject, DuooomiBleSDKDelegate {
|
||||
|
||||
// MARK: - SDK Config(demo 内可改,持久化到 UserDefaults)
|
||||
|
||||
@Published var configOwner: String {
|
||||
didSet { defaults.set(configOwner, forKey: Self.keyOwner) }
|
||||
@Published var configBrand: String {
|
||||
didSet { defaults.set(configBrand, forKey: Self.keyBrand) }
|
||||
}
|
||||
@Published var configApiKey: String {
|
||||
didSet { defaults.set(configApiKey, forKey: Self.keyApiKey) }
|
||||
@@ -47,28 +47,28 @@ final class DemoViewModel: NSObject, ObservableObject, DuooomiBleSDKDelegate {
|
||||
// MARK: - Internals
|
||||
|
||||
private let defaults = UserDefaults.standard
|
||||
private static let keyOwner = "demo.config.owner"
|
||||
private static let keyBrand = "demo.config.brand"
|
||||
private static let keyApiKey = "demo.config.apiKey"
|
||||
private static let keyScanPrefix = "demo.config.scanPrefix"
|
||||
|
||||
/// demo 调试默认值(仅当 UserDefaults 没存过时使用)。秘钥从 DemoSecrets 读,避免泄露到仓库。
|
||||
private static let defaultOwner = DemoSecrets.owner
|
||||
private static let defaultBrand = DemoSecrets.brand
|
||||
private static let defaultApiKey = DemoSecrets.apiKey
|
||||
private static let defaultScanPrefix = DemoSecrets.scanNamePrefix
|
||||
|
||||
override init() {
|
||||
let d = UserDefaults.standard
|
||||
let owner = d.string(forKey: Self.keyOwner) ?? Self.defaultOwner
|
||||
let brand = d.string(forKey: Self.keyBrand) ?? Self.defaultBrand
|
||||
let apiKey = d.string(forKey: Self.keyApiKey) ?? Self.defaultApiKey
|
||||
let scanPrefix = d.string(forKey: Self.keyScanPrefix) ?? Self.defaultScanPrefix
|
||||
|
||||
self.configOwner = owner
|
||||
self.configBrand = brand
|
||||
self.configApiKey = apiKey
|
||||
self.configScanPrefix = scanPrefix
|
||||
|
||||
self.sdk = DuooomiBleSDK(config: .init(
|
||||
apiKey: apiKey,
|
||||
owner: owner,
|
||||
brand: brand,
|
||||
scanNamePrefix: scanPrefix
|
||||
))
|
||||
|
||||
@@ -82,7 +82,7 @@ final class DemoViewModel: NSObject, ObservableObject, DuooomiBleSDKDelegate {
|
||||
func reloadSDK() {
|
||||
let new = DuooomiBleSDK(config: .init(
|
||||
apiKey: configApiKey,
|
||||
owner: configOwner,
|
||||
brand: configBrand,
|
||||
scanNamePrefix: configScanPrefix
|
||||
))
|
||||
new.delegate = self
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
//
|
||||
// 首次 clone 后请:
|
||||
// cp demo/Sources/DemoSecrets.template.swift demo/Sources/DemoSecrets.swift
|
||||
// 然后编辑 DemoSecrets.swift 填入真实 apiKey / owner。
|
||||
// 然后编辑 DemoSecrets.swift 填入真实 apiKey / brand。
|
||||
//
|
||||
// `demo/Sources/DemoSecrets.swift` 已加入 .gitignore,本地修改不会被 commit。
|
||||
import Foundation
|
||||
|
||||
enum DemoSecrets {
|
||||
static let apiKey: String = ""
|
||||
static let owner: String = "xmly"
|
||||
static let brand: String = "xmly"
|
||||
static let scanNamePrefix: String = "Duooomi-"
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ struct WrapperTestView: View {
|
||||
private var configSection: some View {
|
||||
Section("SDK Config(修改后点 Reload 生效)") {
|
||||
HStack {
|
||||
Text("x-owner").frame(width: 90, alignment: .leading)
|
||||
TextField("owner", text: $viewModel.configOwner)
|
||||
Text("brand").frame(width: 90, alignment: .leading)
|
||||
TextField("brand", text: $viewModel.configBrand)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
@@ -90,7 +90,7 @@ struct WrapperTestView: View {
|
||||
}
|
||||
Button("Reload SDK") {
|
||||
viewModel.reloadSDK()
|
||||
log("SDK reloaded with owner=\(viewModel.configOwner), prefix=\(viewModel.configScanPrefix)", level: .success)
|
||||
log("SDK reloaded with brand=\(viewModel.configBrand), prefix=\(viewModel.configScanPrefix)", level: .success)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user