gpt4 book ai didi

ios - CFBundleShortVersionString 返回错误的版本

转载 作者:搜寻专家 更新时间:2023-10-31 22:39:50 25 4
gpt4 key购买 nike

我们通过 CFBundleShortVersionString 将应用程序的当前版本与我们后端的版本进行比较,以确定我们是否要强制用户更新。出于某种原因,在发布新版本的前 24 小时内,CFBundleShortVersionString 返回错误的版本。到目前为止,我们已经尝试了多种解决方案,但似乎都没有奏效。这是我们用来比较的简化版本:

func needToUpdate(completion: @escaping (Bool) -> Void) {
guard let currentVersion = Foundation.Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,
let currentVersionInt = Int(currentVersion.replacingOccurrences(of: ".", with: ""))
else { completion(false); return }

let versionInt = Int((versionObject.version ?? "0").replacingOccurrences(of: ".", with: "")) ?? 0

completion(currentVersionInt < versionInt)
}

此外,此问题仅在应用程序发布到应用程序商店后才会发生,因此我们无法在 xcode 中对其进行调试。我们曾尝试在午夜发布更新,但用户在早上仍然打电话说他们已更新应用程序,但弹出窗口仍然出现。知道是什么原因造成的吗?

最佳答案

不要将版本转换为 int,因为它可能会在版本号大于 9 时失败,例如1.10.0变成1100,大于2.1.0,变成210

您可以将结果字符串直接与 .compare() 进行比较,例如 "1.10.0".compare("2.1.0") ,它返回一个 ComparisonResult

关于ios - CFBundleShortVersionString 返回错误的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49012566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com