- 添加 expiresAt 和 refreshUserSig 参数支持自动续签 - 修改 PushSDK 初始化方式,自动完成设备注册和厂商初始化 - 调整过期续签策略,从提前 15 分钟改为提前 5 分钟触发 - 重构 RN SDK 文档结构,简化安装和使用方式 - 更新统一登录流程,支持 profile 信息传递 - 添加 IM 数据库自动隔离功能 - 修复 Android 群消息聚合问题 - 补充自动化测试验证和错误处理机制
113 行
3.6 KiB
Swift
113 行
3.6 KiB
Swift
import SwiftUI
|
|
import XuqmSDK
|
|
|
|
@MainActor
|
|
final class UpdateViewModel: ObservableObject {
|
|
@Published var isChecking = false
|
|
@Published var updateInfo: AppUpdateInfo?
|
|
@Published var message: String?
|
|
|
|
func checkUpdate() {
|
|
isChecking = true
|
|
message = nil
|
|
Task {
|
|
do {
|
|
let info = try await UpdateSDK.shared.checkAppUpdate(currentVersionCode: 1)
|
|
updateInfo = info
|
|
if !info.needsUpdate {
|
|
message = "已是最新版本"
|
|
}
|
|
isChecking = false
|
|
} catch {
|
|
message = "检查失败: \(error.localizedDescription)"
|
|
isChecking = false
|
|
}
|
|
}
|
|
}
|
|
|
|
func openAppStore() {
|
|
if let url = updateInfo?.appStoreUrl, !url.isEmpty {
|
|
UpdateSDK.shared.openAppStore(url: url)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct UpdateCheckView: View {
|
|
@StateObject private var viewModel = UpdateViewModel()
|
|
|
|
var body: some View {
|
|
VStack(spacing: 20) {
|
|
Spacer().frame(height: 40)
|
|
|
|
Text("版本更新")
|
|
.font(.title2)
|
|
.fontWeight(.bold)
|
|
|
|
if let info = viewModel.updateInfo, info.needsUpdate {
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
Text("发现新版本: \(info.versionName ?? "")")
|
|
.font(.headline)
|
|
|
|
if let changeLog = info.changeLog, !changeLog.isEmpty {
|
|
Text("更新说明: \(changeLog)")
|
|
.font(.body)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
|
|
if info.forceUpdate == true {
|
|
Text("强制更新")
|
|
.font(.caption)
|
|
.foregroundStyle(.red)
|
|
}
|
|
|
|
Button {
|
|
viewModel.openAppStore()
|
|
} label: {
|
|
Text("前往 App Store")
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(Color.accentColor)
|
|
.foregroundStyle(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
}
|
|
}
|
|
.padding()
|
|
.background(Color.gray.opacity(0.15))
|
|
.clipShape(RoundedRectangle(cornerRadius: 16))
|
|
.padding(.horizontal)
|
|
} else {
|
|
if let msg = viewModel.message {
|
|
Text(msg)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
|
|
Button {
|
|
viewModel.checkUpdate()
|
|
} label: {
|
|
HStack {
|
|
if viewModel.isChecking {
|
|
ProgressView()
|
|
}
|
|
Text(viewModel.isChecking ? "检查中…" : "检查更新")
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(Color.accentColor)
|
|
.foregroundStyle(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
}
|
|
.disabled(viewModel.isChecking)
|
|
.padding(.horizontal)
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
.onAppear {
|
|
if viewModel.updateInfo == nil && !viewModel.isChecking {
|
|
viewModel.checkUpdate()
|
|
}
|
|
}
|
|
}
|
|
}
|