|
|
|
@ -16,6 +16,7 @@ struct StsConfig { |
|
|
|
let agentId: String |
|
|
|
var cmei: String = "" |
|
|
|
var mac: String = "" |
|
|
|
var firmwareVersion: String = "" |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - StsAgent |
|
|
|
@ -88,9 +89,9 @@ class StsAgent: NSObject { |
|
|
|
super.init() |
|
|
|
let sessionConfig = URLSessionConfiguration.default |
|
|
|
urlSession = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: OperationQueue()) |
|
|
|
os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ mac=%{public}@ hasSecret=%{public}@", |
|
|
|
os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ mac=%{public}@ firmwareVersion=%{public}@ hasSecret=%{public}@", |
|
|
|
log: logger, type: .info, |
|
|
|
config.productId, config.deviceNo, config.deviceId, config.cmei, config.mac, |
|
|
|
config.productId, config.deviceNo, config.deviceId, config.cmei, config.mac, config.firmwareVersion, |
|
|
|
config.deviceSecret.isEmpty ? "false" : "true") |
|
|
|
// 与 Android 行为对齐:凭证已有时立即尝试上报一次心跳(受 1 小时冷却保护) |
|
|
|
if !config.deviceSecret.isEmpty && !config.deviceId.isEmpty { |
|
|
|
@ -113,6 +114,13 @@ class StsAgent: NSObject { |
|
|
|
os_log("updateMac: mac 已更新为 %{public}@", log: logger, type: .info, mac) |
|
|
|
} |
|
|
|
|
|
|
|
/// 动态更新固件版本(设备连接后由 BLE 上报,首次初始化时通常尚未获取到) |
|
|
|
func updateFirmwareVersion(_ firmwareVersion: String) { |
|
|
|
guard !firmwareVersion.isEmpty, firmwareVersion != config.firmwareVersion else { return } |
|
|
|
config.firmwareVersion = firmwareVersion |
|
|
|
os_log("updateFirmwareVersion: firmwareVersion 已更新为 %{public}@", log: logger, type: .info, firmwareVersion) |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - 公共接口 |
|
|
|
|
|
|
|
func startCall() { |
|
|
|
@ -241,8 +249,8 @@ class StsAgent: NSObject { |
|
|
|
return |
|
|
|
} |
|
|
|
defaults.set(now, forKey: HEARTBEAT_PREFS_KEY) |
|
|
|
os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@ mac=%{public}@", |
|
|
|
log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei, config.mac) |
|
|
|
os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@ mac=%{public}@ firmwareVersion=%{public}@", |
|
|
|
log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei, config.mac, config.firmwareVersion) |
|
|
|
|
|
|
|
let urlStr = "https://ivs.chinamobiledevice.com:11443/v2/customer/device/report" |
|
|
|
guard let url = URL(string: urlStr) else { return } |
|
|
|
@ -257,7 +265,7 @@ class StsAgent: NSObject { |
|
|
|
"netType": "WiFi", |
|
|
|
"platform": "", |
|
|
|
"sdkVersion": "ai_http_1.0", |
|
|
|
"firmwareVersion": "1.0.0", |
|
|
|
"firmwareVersion": config.firmwareVersion, |
|
|
|
"imei": "", |
|
|
|
"cmei": config.cmei, |
|
|
|
"mac": config.mac, |
|
|
|
|