- 为 Android、Flutter、iOS 和 RN SDK 的 Jenkinsfile 添加模块化版本控制 - 引入版本升级策略选择(major/minor/patch)和自定义版本号功能 - 实现多模块独立版本管理和选择性构建发布 - 更新 iOS SDK Package.swift 以支持独立模块化库 - 修改 iOS SDK podspec 文件以适应新的标签命名约定 - 优化 Jenkins 构建流程以支持按需选择特定模块进行构建和发布 - 修复 iOS 测试中的可选类型转换问题以提高代码健壮性
33 行
1.2 KiB
Swift
33 行
1.2 KiB
Swift
import Foundation
|
|
|
|
public enum CommonApiClient {
|
|
|
|
public static func postJSON(urlString: String, body: [String: Any]) async throws -> [String: Any] {
|
|
guard let url = URL(string: urlString) else {
|
|
throw URLError(.badURL)
|
|
}
|
|
|
|
var request = URLRequest(url: url)
|
|
request.httpMethod = "POST"
|
|
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
request.setValue("application/json", forHTTPHeaderField: "Accept")
|
|
request.httpBody = try JSONSerialization.data(withJSONObject: body)
|
|
|
|
let (data, response) = try await URLSession.shared.data(for: request)
|
|
guard let http = response as? HTTPURLResponse else {
|
|
throw URLError(.badServerResponse)
|
|
}
|
|
|
|
let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] ?? [:]
|
|
guard (200..<300).contains(http.statusCode) else {
|
|
throw NSError(
|
|
domain: "CommonApiClient",
|
|
code: http.statusCode,
|
|
userInfo: [NSLocalizedDescriptionKey: json["message"] as? String ?? "HTTP \(http.statusCode)"]
|
|
)
|
|
}
|
|
|
|
return json
|
|
}
|
|
}
|