我正在通过请求http://itunes.apple.com/lookup?bundleId=(identifier从appStore获取信息字典,并收到1.8.2,但是在appStore版本中是1.8.3,如果我在iPhone上设置了app-有关应用程序版本的本地信息是正确的1.8.3,为什么来自appStore请求的版本号错误?
groupBy
}
//要使用它,我打电话:
func isUpdateAvailable(completion: @escaping (Bool?, Error?) -> Void) throws -> URLSessionDataTask {
guard let info = Bundle.main.infoDictionary,
let currentVersion = info["CFBundleShortVersionString"] as? String,
let identifier = info["CFBundleIdentifier"] as? String,
let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)") else {
throw VersionError.invalidBundleInfo
}
print("currentVersion: \(currentVersion)")
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
do {
if let error = error { throw error }
guard let data = data else { throw VersionError.invalidResponse }
let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any]
guard let result = (json?["results"] as? [Any])?.first as? [String: Any], let version = result["version"] as? String else {
throw VersionError.invalidResponse
}
print("AppStore version: \(version)")
completion(version != currentVersion, nil)
} catch {
completion(nil, error)
}
}
task.resume()
return task
答案 0 :(得分:0)
使用https:
代替http:
作为分发包ID。即使在App Store显示正确的版本后,我也注意到了同样的事情。最近几个月,Apple版本的服务器发生了一些变化。