1. 程式人生 > 其它 >iOS是否稽核需要關閉一些操作

iOS是否稽核需要關閉一些操作

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

}