func getAppVersionNumber() {
let appId = "app的Id号"
// 这里要注意,国内App要使用"https://itunes.apple.com/cn/lookup?id="
// 如果使用"https://itunes.apple.com/lookup?id="这个则获取不到版本号
let urlStr = String.init(format:"https://itunes.apple.com/cn/lookup?id=%@", appId)
let url = URL(string: urlStr)
URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data {
do {
if let jsonObject = try JSONSerialization.jsonObject(with: data) as? [String: Any],
let results = jsonObject["results"] as? [Any],
let firstResult = results.first as? [String: Any],
let version = firstResult["version"] as? String {
print("Latest version: \(version)")
}
} catch {
print("Error parsing JSON: \(error)")
}
}
}.resume()
}
标签:String,版本号,App,iOS,version,let,data,apple
From: https://www.cnblogs.com/StardewWang/p/18199447