I'm using the following code to check whether an update is available or not. But it gave me wrong version number. So, it seems an update is available when actually there's not.
enum VersionError: Error { case invalidResponse, invalidBundleInfo }
static func isUpdateAvailable() throws -> Bool {
guard let info = Bundle.main.infoDictionary,
let currentVersion = info["CFBundleShortVersionString"] as? String,
let identifier = info["CFBundleIdentifier"] as? String,
let url = URL(string: "http:/ throw VersionError.invalidBundleInfo
}
let data = try Data(contentsOf: url)
guard let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any]
else {
throw VersionError.invalidResponse
}
if let result = (json["results"] as? [Any])?.first as? [String: Any],
let version = result["version"] as? String {
print("version: \(version)") //writes 1.1
print("currentVersion: \(currentVersion)") // writes 1.1.1
return version != currentVersion
}
throw VersionError.invalidResponse
}
I downloaded the file manually and the version number there is 1.1.1. as it should be. But the code gives me 1.1. I couldn't find out what is wrong.
By the way, the update has just released today. I think it shouldn't be related with that. It is an Apple bug or am I making something wrong?
The url: http://itunes.apple.com/tr/lookup?bundleId=com.sahin.lingustica