58 行
1.9 KiB
Swift
58 行
1.9 KiB
Swift
|
|
import Foundation
|
||
|
|
import UIKit
|
||
|
|
|
||
|
|
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?
|
||
|
|
}
|
||
|
|
|
||
|
|
public struct RnUpdateInfo: Decodable, Sendable {
|
||
|
|
public let needsUpdate: Bool
|
||
|
|
public let latestVersion: String
|
||
|
|
public let downloadUrl: String
|
||
|
|
public let md5: String
|
||
|
|
public let minCommonVersion: String
|
||
|
|
public let note: 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 }
|
||
|
|
UIApplication.shared.open(storeURL)
|
||
|
|
}
|
||
|
|
|
||
|
|
public func checkRnUpdate(moduleId: String, currentVersion: String) async throws -> RnUpdateInfo {
|
||
|
|
let config = XuqmSDK.shared.requireConfig()
|
||
|
|
return try await ApiClient.shared.request(
|
||
|
|
path: "/api/v1/rn/update/check",
|
||
|
|
queryItems: [
|
||
|
|
URLQueryItem(name: "appId", value: config.appId),
|
||
|
|
URLQueryItem(name: "moduleId", value: moduleId),
|
||
|
|
URLQueryItem(name: "platform", value: "IOS"),
|
||
|
|
URLQueryItem(name: "currentVersion", value: currentVersion),
|
||
|
|
]
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|