Wrong App Store app version number from request http://itunes.apple.com/lookup?bundleId=\(identifier)

I'm getting info dictionary from appStore by request http://itunes.apple.com/lookup?bundleId=(identifier) for my app and receive 1.8.2, but in appStore version is 1.8.3, and if I setup app on iPhone - local info about app version is correct 1.8.3, why the wrong version number is coming from appStore request?

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

}

// To use it I'm call:

_ = try? isUpdateAvailable { (update, error) in
    if let error = error {
        print(error)
    } else if let update = update {
        print(update)
    }
}

Upvotes: 0

Views: 459

Answers (1)

Rahul
Rahul

Reputation: 31

Use https: instead of http: for bundle ID. I noticed same thing even after App Store shows correct version. Something changed in last few months at apple version servers.

Upvotes: 3

Related Questions