- 在UpdateApi接口中新增可选的userId查询参数 - 新增UpdateSDK对象用于统一管理应用更新逻辑 - 实现应用版本检查、下载安装和APK文件处理功能 - 添加下载URL规范化处理逻辑 - 在Flutter SDK中新增update模块实现跨平台更新功能 - 在iOS SDK中新增UpdateSDK类提供应用更新检查接口 - 支持Android和iOS平台的应用商店跳转功能 - 添加React Native SDK的更新检查和插件注册功能 - 实现RN Bundle的检查、下载和缓存机制
45 行
1.3 KiB
Swift
45 行
1.3 KiB
Swift
import Foundation
|
|
#if canImport(UIKit)
|
|
import UIKit
|
|
#endif
|
|
|
|
public struct AppUpdateInfo: Decodable, Sendable {
|
|
public let needsUpdate: Bool
|
|
public let versionName: String?
|
|
public let versionCode: Int?
|
|
public let changeLog: String?
|
|
public let forceUpdate: Bool?
|
|
public let appStoreUrl: String?
|
|
}
|
|
|
|
@MainActor
|
|
public final class UpdateSDK {
|
|
|
|
public static let shared = UpdateSDK()
|
|
private init() {}
|
|
|
|
public func checkAppUpdate(currentVersionCode: Int) async throws -> AppUpdateInfo {
|
|
let config = XuqmSDK.shared.requireConfig()
|
|
let userId = XuqmSDK.shared.currentUserId
|
|
var queryItems = [
|
|
URLQueryItem(name: "appKey", value: config.appKey),
|
|
URLQueryItem(name: "platform", value: "IOS"),
|
|
URLQueryItem(name: "currentVersionCode", value: "\(currentVersionCode)"),
|
|
]
|
|
if let userId, !userId.isEmpty {
|
|
queryItems.append(URLQueryItem(name: "userId", value: userId))
|
|
}
|
|
return try await ApiClient.shared.request(
|
|
path: "/api/v1/updates/app/check",
|
|
queryItems: queryItems
|
|
)
|
|
}
|
|
|
|
public func openAppStore(url: String) {
|
|
guard let storeURL = URL(string: url) else { return }
|
|
#if canImport(UIKit)
|
|
UIApplication.shared.open(storeURL)
|
|
#endif
|
|
}
|
|
}
|