import Foundation import XuqmCoreSDK #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 { await XuqmSDK.shared.awaitInitialization() 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 } }