xcode 虽然应用程序是最新的,但它会给出更新警告

xam8gpfp  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(87)

当登录我写的一个应用程序时,它说“我们有一个新的更新。请更新以继续。”给出警告。但应用程序是最新的。如果我单击“确定”,它会将我重定向到应用程序商店,但没有更新。
如何解决此错误?
Update Alert
我告诉它将应用程序版本与应用程序商店版本进行比较,并相应地给予出更新警告,但它一直在给。

unguejic

unguejic1#

enum VersionError: Error {
    case invalidResponse, invalidBundleInfo
}

@discardableResult
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
    }
        
    let request = URLRequest(url: url, cachePolicy: URLRequest.CachePolicy.reloadIgnoringLocalCacheData)
    
    let task = URLSession.shared.dataTask(with: request) { (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 lastVersion = result["version"] as? String else {
                throw VersionError.invalidResponse
            }
            completion(lastVersion > currentVersion, nil)
        } catch {
            completion(nil, error)
        }
    }
    
    task.resume()
    return task
}

字符串
使用方法:

try? isUpdateAvailable {[self] (update, error) in
                if let error = error {
                    print(error)
                } else if update ?? false {
                    // show alert
                }
            }


我使用的是相同的结构代码,它工作正常,这里是参考链接-> Check if my app has a new version on AppStore

相关问题