1.先获取最新版本号和本地版本号进行对比
2.去掉本地版本号上的 . 处理为Int类型
/// 获取是否需要审核时动态展示内容
/// true:审核通过
/// - Returns: 返回是否审核通过内容
func IsActive() -> Bool {
if let newVersion = YPIndexConfigModel.shared?.appVersionInfo {
if let infoDic = Bundle.main.infoDictionary {
let currentVersion: String = infoDic["CFBundleShortVersionString"] as! String
var currentVersionInt = 0
let currentArray = currentVersion.components(separatedBy: ".")
if currentArray.count == 3 {
currentVersionInt = Int(currentArray[0])! * 100 + Int(currentArray[1])! * 10 + Int(currentArray[2])!
}
var newVersionInt = 0
if let newArray = newVersion.version?.components(separatedBy: ".") {
if newArray.count == 3 {
newVersionInt = Int(newArray[0])! * 100 + Int(newArray[1])! * 10 + Int(newArray[2])!
}
}
if newVersionInt > currentVersionInt {
return true
} else {
if newVersion.active == "0" {
return false
} else {
return true
}
}
}
}else{
if let info = Bundle.main.infoDictionary,
let date = info["AppYupaoReleaseTime"] as? Date,
let length = info["AppYupaoReleaseExamineTime"] as? NSNumber{
//当前时间
let current = Date.init().timeIntervalSince1970
//进入审核的时间
let releaseTime = date.timeIntervalSince1970
//预计的审核所需时间
let count = length.doubleValue * 24 * 60 * 60
//如果超过预估审核时间则视为审核通
return current - releaseTime > count
}
}
return false
}
---------------- 一样的写法 -----------------
/// 检测当前是否线上状态
///
/// - Parameter newVersion: 服务器获取到的versionModel
/// - Returns: 返回是否是线上状态 ture:线上, false:审核中
func CheckActive() -> Bool {
if let newVersion = UserDefaultsGetModel(key: Version_Identitfying) as? AppUpdateModel {
if let infoDic = Bundle.main.infoDictionary {
let currentVersion: String = infoDic["CFBundleShortVersionString"] as! String
var currentVersionInt = 0
let currentArray = currentVersion.components(separatedBy: ".")
if currentArray.count == 3 {
currentVersionInt = Int(currentArray[0])! * 100 + Int(currentArray[1])! * 10 + Int(currentArray[2])!
}
var newVersionInt = 0
if let newArray = newVersion.version?.components(separatedBy: ".") {
if newArray.count == 3 {
newVersionInt = Int(newArray[0])! * 100 + Int(newArray[1])! * 10 + Int(newArray[2])!
}
}
if newVersionInt > currentVersionInt {
return true
}else {
if newVersion.active == 0 {
return false
}else {
return true
}
}
}
}
return false
}