Commit b1b8dbd2 authored by 刘俊宏's avatar 刘俊宏

检测app更新

parent a8f75854
......@@ -18,8 +18,13 @@ class GeliAlertView: UIView {
@IBOutlet weak var leftBtn: UIButton!
@IBOutlet weak var rightBtn: UIButton!
var appStoreVersion:String = ""
@IBAction func leftAction(_ sender: UIButton) {
print("左←边按钮响应")
if appStoreVersion.count != 0 {
//选择了该版本取消更新后不再提示
UserDefaults.standard.setValue(appStoreVersion, forKey: "appStoreVersion")
}
self.removeFromSuperview()
}
@IBAction func rightAction(_ sender: UIButton) {
......
......@@ -9,8 +9,12 @@
import UIKit
import IQKeyboardManagerSwift
import SwiftDate
import Alamofire
import SwiftyJSON
class WorkCViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource ,WorkSelectTimeViewDelegate,WorkItemTableViewCellDelegate,EditWorkCViewControllerDelegate{
class WorkCViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource ,WorkSelectTimeViewDelegate,WorkItemTableViewCellDelegate,EditWorkCViewControllerDelegate, GeliAlertViewDelegate{
@IBOutlet weak var topNavBtn: UIButton!
@IBOutlet weak var contentView: UIView!
......@@ -36,6 +40,8 @@ class WorkCViewController: BaseViewController, UITableViewDelegate, UITableViewD
setTabv()
NotificationCenter.default.addObserver(self, selector: #selector(jpushServiceNotification(notion:)), name: NSNotification.Name(rawValue: "jpushServiceNotification2"), object: nil)
updateApp()
}
//MARK:--jpushServiceNotification
@objc func jpushServiceNotification(notion:Notification) {
......@@ -559,5 +565,60 @@ class WorkCViewController: BaseViewController, UITableViewDelegate, UITableViewD
}
//MARK:--检测app更新
func updateApp(){
let infoDicod = Bundle.main.infoDictionary
let currentVersion:String = infoDicod!["CFBundleShortVersionString"] as! String
Alamofire.request("http://itunes.apple.com/cn/lookup?id=1515684912")
.responseJSON { response in
switch response.result.isSuccess {
case true:
if let value = response.result.value {
let json = JSON(value)
print(json)
if let appStoreVersion = json["results"][0]["version"].string {
if currentVersion.caseInsensitiveCompare(appStoreVersion).rawValue == -1 {
print("需要更新哦+++")
let oldappStoreVersion = UserDefaults.standard.object(forKey: "appStoreVersion")
if oldappStoreVersion != nil {
if appStoreVersion != oldappStoreVersion as!String {
self.updateStr = json["results"][0]["trackViewUrl"].string!
let alertView = GeliAlertView(frame: self.view.window!.bounds)
alertView.delegate = self;
alertView.tishiLbl.text = json["results"][0]["releaseNotes"].string
alertView.titileLbl.text = "有新版本可更新"
alertView.rightBtn.setAttributedTitle(NSAttributedString(string: "去更新"), for: .normal)
alertView.rightBtn.tag = 1515684912
alertView.appStoreVersion = appStoreVersion
self.view.window?.addSubview(alertView)
}
}else{
self.updateStr = json["results"][0]["trackViewUrl"].string!
let alertView = GeliAlertView(frame: self.view.window!.bounds)
alertView.delegate = self;
alertView.tishiLbl.text = json["results"][0]["releaseNotes"].string
alertView.titileLbl.text = "有新版本可更新"
alertView.rightBtn.setAttributedTitle(NSAttributedString(string: "去更新"), for: .normal)
alertView.rightBtn.tag = 1515684912
alertView.appStoreVersion = appStoreVersion
self.view.window?.addSubview(alertView)
}
}else{
print("不需要更新哦---")
}
}
}
case false: break
//错误
}
}
}
var updateStr:String = ""
func sureGeliAlertViewAction(sender: UIButton) {
if sender.tag == 1515684912 {
UIApplication.shared.open(URL(string: updateStr)!)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment