2026-04-21 22:07:29 +08:00
|
|
|
import Foundation
|
2026-04-28 10:27:23 +08:00
|
|
|
|
|
|
|
|
#if canImport(UIKit)
|
2026-04-21 22:07:29 +08:00
|
|
|
import UIKit
|
2026-04-28 10:27:23 +08:00
|
|
|
#elseif canImport(AppKit)
|
|
|
|
|
import AppKit
|
|
|
|
|
#endif
|
2026-04-21 22:07:29 +08:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
return try await ApiClient.shared.request(
|
|
|
|
|
path: "/api/v1/updates/app/check",
|
|
|
|
|
queryItems: [
|
|
|
|
|
URLQueryItem(name: "appId", value: config.appId),
|
|
|
|
|
URLQueryItem(name: "platform", value: "IOS"),
|
|
|
|
|
URLQueryItem(name: "currentVersionCode", value: "\(currentVersionCode)"),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func openAppStore(url: String) {
|
|
|
|
|
guard let storeURL = URL(string: url) else { return }
|
2026-04-28 10:27:23 +08:00
|
|
|
#if canImport(UIKit)
|
2026-04-21 22:07:29 +08:00
|
|
|
UIApplication.shared.open(storeURL)
|
2026-04-28 10:27:23 +08:00
|
|
|
#elseif canImport(AppKit)
|
|
|
|
|
NSWorkspace.shared.open(storeURL)
|
|
|
|
|
#endif
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
}
|