swift4.0 版本号判断

2019-07-07  本文已影响0人  onebook_

取当前版本号

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
上一篇 下一篇

猜你喜欢

热点阅读