- XuqmSDK: autoInitialize() validates iosBundleId; awaitInitialization() with CheckedContinuation - LicenseSDK: await XuqmSDK initialization before license operations - UpdateSDK: await XuqmSDK init before checkAppUpdate - LicenseModels: add packageName, iosBundleId, harmonyBundleName, serverUrl fields Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
46 行
1.4 KiB
Swift
46 行
1.4 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 {
|
|
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
|
|
}
|
|
}
|