SCommonViewController.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. self.showMessage(title: "更新校验中,请稍候...")
  25. }
  26. @objc private func updateVersion(_ response:AnyObject?){
  27. print("update be callbacked")
  28. if let obj = response {
  29. self.dismissProgressHUD()
  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. self.showSuccess(title: "已经是最新版本")
  41. }
  42. }
  43. @IBAction func clearCacheAction(_ sender: UIButton) {
  44. self.showMessage(title: "正在收集...")
  45. let fileSize = SZKCleanCache.folderSizeAtPath()
  46. let msg = "检测到可以清理的缓存大小为\(fileSize)M,是否立即清除?"
  47. //let msgAttrib = msg.color(RGB(155, g: 155, b: 155))
  48. let alertController = UIAlertController(title: "", message: msg, preferredStyle: .alert)
  49. let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
  50. self.clearCache()
  51. }
  52. let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
  53. alertController.addAction(okAction)
  54. alertController.addAction(cancelAction)
  55. self.dismissProgressHUD()
  56. self.present(alertController, animated: true, completion: nil)
  57. }
  58. private func clearCache() {
  59. self.group.enter()
  60. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  61. Shared.imageCache.removeAll({
  62. SZKCleanCache.cleanCache({
  63. print("图片缓存清除。。。")
  64. self.group.leave()
  65. })
  66. })
  67. }))
  68. self.group.enter()
  69. DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
  70. let types = WKWebsiteDataStore.allWebsiteDataTypes()
  71. WKWebsiteDataStore.default().removeData(ofTypes: types, modifiedSince: Date(timeIntervalSince1970: 0), completionHandler: {
  72. print("浏览器缓存清除")
  73. self.group.leave()
  74. })
  75. }))
  76. self.group.notify(queue: DispatchQueue.main) {
  77. self.showSuccess(title: "清理完成")
  78. self.notify()
  79. }
  80. }
  81. private func notify() {
  82. // 通知门户页面刷新 因为清除了浏览器缓存 没有cookie了 需要重新加载webview
  83. NotificationCenter.default.post(name: OONotification.reloadPortal.notificationName, object: nil)
  84. }
  85. /*
  86. // MARK: - Navigation
  87. // In a storyboard-based application, you will often want to do a little preparation before navigation
  88. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  89. // Get the new view controller using segue.destinationViewController.
  90. // Pass the selected object to the new view controller.
  91. }
  92. */
  93. }