SCommonViewController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // SCommonViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/13.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import EZSwiftExtensions
  10. import WebKit
  11. class SCommonViewController: UITableViewController {
  12. @IBOutlet weak var clearCacheButton: UIButton!
  13. let group = DispatchGroup()
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do any additional setup after loading the view.
  17. }
  18. override func didReceiveMemoryWarning() {
  19. super.didReceiveMemoryWarning()
  20. // Dispose of any resources that can be recreated.
  21. }
  22. @IBAction func checkUpdateVersion(_ sender: UIButton) {
  23. PgyUpdateManager.sharedPgy().checkUpdate(withDelegete: self, selector: #selector(updateVersion(_:)))
  24. ProgressHUD.show("更新校验中,请稍候...", interaction: false)
  25. }
  26. @objc private func updateVersion(_ response:AnyObject?){
  27. print("update be callbacked")
  28. if let obj = response {
  29. ProgressHUD.dismiss()
  30. //print(obj)
  31. let appURLString = obj["downloadURL"]
  32. if let appURL = URL(string: appURLString as! String) {
  33. if UIApplication.shared.canOpenURL(appURL) {
  34. if UIApplication.shared.openURL(appURL) {
  35. PgyUpdateManager.sharedPgy().updateLocalBuildNumber()
  36. }
  37. }
  38. }
  39. }else{
  40. ProgressHUD.show("已经是最新版本")
  41. Timer.after(0.5, {
  42. DispatchQueue.main.async {
  43. ProgressHUD.dismiss()
  44. }
  45. })
  46. }
  47. }
  48. @IBAction func clearCacheAction(_ sender: UIButton) {
  49. ProgressHUD.show("正在收集...", interaction: false)
  50. let fileSize = SZKCleanCache.folderSizeAtPath()
  51. let msg = "检测到可以清理的缓存大小为\(fileSize)M,是否立即清除?"
  52. //let msgAttrib = msg.color(RGB(155, g: 155, b: 155))
  53. let alertController = UIAlertController(title: "", message: msg, preferredStyle: .alert)
  54. let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
  55. self.clearCache()
  56. }
  57. let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
  58. alertController.addAction(okAction)
  59. alertController.addAction(cancelAction)
  60. ProgressHUD.dismiss()
  61. self.present(alertController, animated: true, completion: nil)
  62. }
  63. private func clearCache() {
  64. self.group.enter()
  65. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  66. Shared.imageCache.removeAll({
  67. SZKCleanCache.cleanCache({
  68. print("图片缓存清除。。。")
  69. self.group.leave()
  70. })
  71. })
  72. }))
  73. self.group.enter()
  74. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  75. let types = WKWebsiteDataStore.allWebsiteDataTypes()
  76. WKWebsiteDataStore.default().removeData(ofTypes: types, modifiedSince: Date(timeIntervalSince1970: 0), completionHandler: {
  77. print("浏览器缓存清除")
  78. self.group.leave()
  79. })
  80. }))
  81. self.group.notify(queue: DispatchQueue.main) {
  82. ProgressHUD.showSuccess("清理完成")
  83. self.notify()
  84. }
  85. }
  86. private func notify() {
  87. // 通知门户页面刷新 因为清除了浏览器缓存 没有cookie了 需要重新加载webview
  88. NotificationCenter.default.post(name: Notification.Name("reloadPortal"), object: nil)
  89. }
  90. /*
  91. // MARK: - Navigation
  92. // In a storyboard-based application, you will often want to do a little preparation before navigation
  93. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  94. // Get the new view controller using segue.destinationViewController.
  95. // Pass the selected object to the new view controller.
  96. }
  97. */
  98. }