swift4.0 版本号判断

取当前版本号

let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""

取之前的版本号

let docDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let path: String = (docDir as? NSString)?.appendingPathComponent("path.json") ?? ""
let sandBoxVersion = try? (String(contentsOfFile: path))

将当前版本号保存在沙盒中

 try? currentVersion.write(toFile: path, atomically: true, encoding: .utf8)

返回两个版本号,是否一致

 return currentVersion != sandBoxVersion

你可能感兴趣的:(swift4.0 版本号判断)